Breaking a Ruby code snippet into a sequence of classes and their connecting methods.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


Build Status Gem Version

CodeBreaker breaks a line of Ruby code into its receiver classes and the methods that are called on them.

The idea behind this is to make global lines of code like the following one testable:

sum = Rational(2, 3) + 4

By breaking down this line into the receiver classes and called methods you can check e.g. whether a code snippet assigns the sum of a Rational and an Integer to a variable with the name sum.

Testing global code snippets might be important for testing the code of simple programming tasks in learning tools like Daigaku.


Add this line to your application's Gemfile:

gem 'code_breaker'

And then execute:

$ bundle

Or install it yourself as:

$ gem install 'code_breaker'


You can break a Ruby code snippet into its receivers and called method:

require 'code_breaker'

code_snippet = 'crazy_number = Rational(3, 5) + 42 - Complex(2.3, 6.4) * 1.2'
# for Ruby < v2.4.0:
# => {:lvasgn=>[:crazy_number, [Rational, :+, Fixnum, :-, Complex, :*, Float]]}
# for Ruby >= v2.4.0:
# => {:lvasgn=>[:crazy_number, [Rational, :+, Integer, :-, Complex, :*, Float]]}

code_snippet = '"hello" + "World"'
# => [String, :+, String]

You can also use the Parser class directly:

code_snippet = '"hello" + "World"'

parser =
# => [String, :+, String]

# => [String, :+, String]

# => "\"hello\"+\"world\""

Implemented syntax

For an overview of the implemented syntax and examples for certain parsed Ruby statement please see the project's Wiki.


After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to


Bug reports and pull requests are welcome on GitHub at This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.


The gem is available as open source under the terms of the MIT License.