Skip to content

Commit 907b271

Browse files
committed
Add description and examples
1 parent 7f64553 commit 907b271

1 file changed

Lines changed: 42 additions & 6 deletions

File tree

README.md

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,64 @@
11
# CodeBreaker
22

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.
45

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).
618

719
## Installation
820

921
Add this line to your application's Gemfile:
1022

1123
```ruby
12-
gem 'code_breaker'
24+
gem 'code_breaker', github: 'daigaku-ruby/code_breaker'
1325
```
1426

1527
And then execute:
1628

1729
$ bundle
1830

19-
Or install it yourself as:
31+
Or download and install it yourself as:
2032

21-
$ gem install code_breaker
33+
$ git clone git@github.com:daigaku-ruby/code_breaker.git
34+
$ cd code_breaker
35+
$ rake install
2236

2337
## Usage
2438

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+
```
2662

2763
## Development
2864

0 commit comments

Comments
 (0)