Ruby
Learn how to solve CodeCrafters challenges in Ruby
Local development
To run the code for your challenge locally, you’ll need ruby
installed. Our test runners use version 3.3
(as of May 2024).
The script for your challenge (like ./spawn_redis_server.sh
) will run your code using Bundler, a dependency manager which comes preinstalled with Ruby. It looks something like this:
File structure
- The files for your solution are placed in the
app/
directory. app/main.rb
is the entrypoint of the project.
Adding more files
You can add more files and directories to app/
. The test runner will include them when compiling your code.
For example, if you added a file at app/foo.rb
, you could use it like so:
Adding dependencies
Gemfile
lists your project’s dependencies. You can add dependencies by specifying the name of the gem and optionally the version.
For example, To add the nokogiri
gem, add the following line to your Gemfile
:
Then run the following command to install it:
This command will also update your Gemfile.lock
file.