Need help with ruby?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

385 Stars 394 Forks MIT License 2.3K Commits 85 Opened issues


Exercism exercises in Ruby.

Services available


Need anything else?

Contributors list

Exercism Ruby Track

Configlet Status Exercise Test Status Join the chat at

Exercism Exercises in Ruby

Table of Contents


You'll need a recent (2.6+) version of Ruby, but that's it. Minitest ships with the language, so you're all set.

Anatomy of an Exercise

The files for an exercise live in

. The slug for an exercise is a unique nickname composed of a-z (lowercase) and -, e.g.
. Inside its directory, each exercise has:
  • a test suite,
  • an example solution,


 is the underscored version of the exercise's slug,

If the exercise has a test generator, the directory will also contain:

  • the test generator,

A few exercises use a custom test template:

  • .meta/generator/test_template.erb

Canonical Data

Most exercises can be generated from shared inputs/outputs, called canonical data (see Generated Test Suites below). To find out whether a test has canonical data, check the problem-specifications repo.

Running the Tests

Run the tests using

, rather than
ruby path/to/the_test.rb
knows to look for the example solution and to disable skips. Just tell
the name of your problem and you are set:
rake test:clock

To pass arguments to the test command, like

for example, you can run the following:
rake test:clock -- -p

To run a subset of the tests, use a regular expression. For example, if tests exist that are named identicalto4_places, and identical, then we can run both tests with

rake test:hamming -- -p -n="/identical/"

Note that flags which have an attached value, like above, must take the form

and if
has spaces
-flag="value with spaces"

Generated Test Suites

Generated test suites use the


Before using the cli it is recommended you run

bundle install
from within the ruby directory to install/update any required gems.

While many of the exercises which have canonical data already have generators, some do not. To find out whether an exercise has a generator, run

bin/generate -h

In addition to a usage message, the

flag lists all exercises with a generator. If a generator is available for your exercise, you can

If not, you will need to implement a new generator.

Generated exercises depend on the the shared metadata, which must be cloned to the same directory that contains your clone of the ruby repository:

tree -L 1 ~/code/exercism
├── problem-specifications
└── ruby

To explain a bit more, you must follow this commands step-by-step:-

  $ mkdir exercism
  $ cd exercism

Fork the exercism/ruby

Fork the exercism/problem-specifications

Now you need to clone both the above repositories ``` bash

$ git clone $ git clone

Next, you need to [configure the remote]( and [synchronize]( it.

Make sure you have synced up local master branch and upstream master branch. Since this will keep local master branch up-to-date with the upstream repository. Thereby, you will able to get the latest commits.

Regenerating a Test Suite

From time to time, the canonical data for an exercise's tests changes, and we need to keep the Ruby version's tests synced up. Regenerating these tests is a quick and easy way to help maintain the track and get involved!

If it's your first time cloning/contributing to the repository, you'll need to install any dependencies via bundle:

```bash bundle install

Be sure that you're working on the most up-to-date version of the repo. From the root of your copy of the repository:

# Add the exercism repo as upstream if you haven't yet:
git remote add upstream

Pull down any changes

git fetch upstream

Merge any upstream changes with your master branch

git checkout master git merge upstream/master

Depending on your git workflow preferences and the state of your local repo, you may want to do some rebasing. See the rebasing documentation for more information.

The generator also depends on the presence of Exercism's

repository (see the file tree in the section above). Make sure you've got an up-to-date version of the specifications in a
folder that's in a parallel directory to your local copy of the

To check which problems have possibly been updated, run:

bin/generate --all

This will autogenerate all of the test cases for which generators exist. Use

git diff
(or your preferred method) to find out which test files have changed. Some exercises will update because someone updated the description or other exercise metadata. Others will change because the actual test suite has changed.

Once everything has been regenerated and updated, you're almost ready to submit your changes via pull request. Please be sure to only update one exercise per pull request. Also, please follow the guidelines in the Pull Requests section, being sure to follow the pattern of

: Regenerate Tests
, where slug is the slug of the exercise that your pull request is regenerating.

Changing a Generated Exercise

Do not edit

. Any changes you make will be overwritten when the test suite is regenerated.

There are two reasons why a test suite might change:

  1. the tests need to change (an incorrect expectation, a missing edge case, etc)
  2. there might be issues with the style or boilerplate

In the first case, the changes need to be made to the

file for the exercise, which lives in the problem-specifications repository.
├── canonical-data.json
└── metadata.yml

This change will need to be submitted as a pull request to the problem-specifications repository. This pull request needs to be merged before you can regenerate the exercise.

Changes that don't have to do directly with the test inputs and outputs should be made to the exercise's test case generator, discussed in implementing a new generator, next. Then you can regenerate the exercise with


Implementing a Generator

An exercise's test case generator class produces the code that goes inside the minitest

methods. An exercise's generator lives in

The test case generator is a derived class of

does most of the work of extracting the canonical data and provides you with some accessor methods to access the values you are likely to need to use.

For example:

If a section of the

file looks like this:
  , { "description": "Bar'ing a name with numbers gives an error"
    , "property"   : "bar"
    , "input"      : {
        "firstName"  : "HAL",
        "lastName"   : "9000"
    , "expected"   : { "error": "You should never bar a number" }

You will be able to access input['firstName'] by the Ruby methods


And the


If there is a property name conflict the "input" version will take precedence, or you can use the

prefixes to disambiguate.

The test template you need to write looks like this:

require 'generator/exercise_case'

class Case < Generator::ExerciseCase

def workload # Example workload: "#{assert}{input.inspect})" end



 is the CamelCased version of the exercise's slug. This
is important, since the generator script will infer the name of the class from

This class must provide the methods used by the test template. A default template that most exercises can (and do) use lives in

. The base class provides methods for the default template for everything except

generates the code for the body of a test, including the assertion and any setup required. The base class provides a variety of assertion and helper methods.

Beyond that, you can implement any helper methods that you need as private methods in your derived class. See below for more information about the intention of #workload

You don't have to do anything other than implement

to use the default template.

If you really must add additional logic to the view template, you can use a custom template. Copy

under your exercise directory and customize. You may need to create

Workload philosophy.

Prioritize educational value over expert comprehension and make sure that things are clear to people who may not be familiar with Minitest and even Ruby.

Provide the information the student needs to derive the code to pass the test in a clear and consistent manner. Illustrate the purpose of the individual elements of the assertion by using meaningful variable names.

Example output from the

detector ='allergy')
anagrams = detector.match(["gallery", "ballerina", "regally", "clergy", "largely", "leading"])
expected = ["gallery", "largely", "regally"]
assert_equal expected, anagrams.sort

Pull Requests

We welcome pull requests that provide fixes to existing test suites (missing tests, interesting edge cases, improved APIs), as well as new problems.

If you're unsure, then go ahead and open a GitHub issue, and we'll discuss the change.

Please submit changes to a single problem per pull request unless you're submitting a general change across many of the problems (e.g. formatting).

You can run (some) of the same checks that we run by running the following tool in your terminal:


If you would like to have these run right before you push your commits, you can activate the hook by running this tool in your terminal:


Thank you so much for contributing! :sparkles:

Style Guide

We have created a minimal set of guidelines for the testing files, which you can take advantage of by installing the

gem. It will use the configuration file located in the root folder,
. When you edit your code, you can simply run
rubocop -D
. It will ignore your example solution, but will gently suggest style for your test code.


option that is suggested is provided to give you the ability to easily ignore the Cops that you think should be ignored. This is easily done by doing
# rubocop:disable CopName
, where the
is replaced appropriately.

For more complete information, see Rubocop.


provides helper functions as discussed above, it remains the responsibility of an exercise's generator to interpret its canonical-data.json data in a stylistically correct manner, e.g. converting string indices to integer indices.


All exercises must have a file, but should not be created manually. The READMEs are constructed using shared metadata, which lives in the problem-specifications repo.

Use the

tool to generate a README from shared metadata:
  1. Clone the problem-specifications repo into an adjacent directory.
  2. Fetch the configlet appropriate for your system:
  3. Generate the readme for a particular exercise:
    bin/configlet generate . --only rotational-cipher

Contributing Guide

If adding a new exercise:

  • a generator should be implemented.
  • a minimal, partial, solution should be able to be pushed, in order to create a WIP pull request.

For an in-depth discussion of how exercism language tracks and exercises work, please see the contributing guide.

If you're just getting started and looking for a helpful way to get involved, take a look at regenerating the test suites, porting an exercise from another language, or creating an automated test generator.

Ruby icon

The Ruby icon is the Vienna.rb logo, and is used with permission. Thanks Floor Dress :)

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.