|
1 | 1 | # CodeBreaker |
2 | 2 |
|
3 | | -Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/code_breaker`. To experiment with that code, run `bin/console` for an interactive prompt. |
| 3 | +CodeBreaker breaks a line of Ruby code into its receiver classes and the methods |
| 4 | +that are called on them. |
4 | 5 |
|
5 | | -TODO: Delete this and the text above, and describe your gem |
| 6 | +The idea behind this is to make global lines of code like the following one testable: |
| 7 | + |
| 8 | +```ruby |
| 9 | +sum = Rational(2, 3) + 4 |
| 10 | +``` |
| 11 | + |
| 12 | +By breaking down this line into the receiver classes and called methods you can |
| 13 | +check e.g. whether a code snippet assigns the sum of a Rational and a Fixnum to |
| 14 | +a variable with the name `sum`. |
| 15 | + |
| 16 | +Testing global code snippets might be important for testing the code of simple |
| 17 | +programming tasks in learning tools like [Daigaku](https://github.com/daigaku-ruby/daigaku). |
6 | 18 |
|
7 | 19 | ## Installation |
8 | 20 |
|
9 | 21 | Add this line to your application's Gemfile: |
10 | 22 |
|
11 | 23 | ```ruby |
12 | | -gem 'code_breaker' |
| 24 | +gem 'code_breaker', github: 'daigaku-ruby/code_breaker' |
13 | 25 | ``` |
14 | 26 |
|
15 | 27 | And then execute: |
16 | 28 |
|
17 | 29 | $ bundle |
18 | 30 |
|
19 | | -Or install it yourself as: |
| 31 | +Or download and install it yourself as: |
20 | 32 |
|
21 | | - $ gem install code_breaker |
| 33 | + $ git clone git@github.com:daigaku-ruby/code_breaker.git |
| 34 | + $ cd code_breaker |
| 35 | + $ rake install |
22 | 36 |
|
23 | 37 | ## Usage |
24 | 38 |
|
25 | | -TODO: Write usage instructions here |
| 39 | +You can break a Ruby code snippet into its receivers and called method: |
| 40 | + |
| 41 | +```ruby |
| 42 | +require 'code_breaker' |
| 43 | + |
| 44 | +code_snippet = 'crazy_number = Rational(3, 5) + 42 - Complex(2.3, 6.4) * 1.2' |
| 45 | +CodeBreaker.parse(code_snippet) |
| 46 | +# => [Rational, :+, Fixnum, :-, Complex, :*, Float] |
| 47 | +``` |
| 48 | + |
| 49 | +You can also use the Parser class directly: |
| 50 | + |
| 51 | +```ruby |
| 52 | +parser = CodeBreaker::Parser.new(code_snippet) |
| 53 | +parser.run |
| 54 | +# => [Rational, :+, Fixnum, :-, Complex, :*, Float] |
| 55 | + |
| 56 | +parser.input |
| 57 | +# => 'crazy_number = Rational(3, 5) + 42 - Complex(2.3, 6.4) * 1.2' |
| 58 | + |
| 59 | +parser.output |
| 60 | +# => [Rational, :+, Fixnum, :-, Complex, :*, Float] |
| 61 | +``` |
26 | 62 |
|
27 | 63 | ## Development |
28 | 64 |
|
|
0 commit comments