Rubic
Rubic is a Ruby REPL. Aside from behaving like IRB, it also borrows some concepts from older BASIC REPLs. Mainly, this involves writing programs by specifying line numbers. For information on commands, use help
. Otherwise, a basic example session lives below.
> 10 puts "what is your name?"
> 20 name = gets.chomp
> 30 puts "nice to meet you, #{name}!"
>
> list
10 puts "what is your name?"
20 name = gets.chomp
30 puts "nice to meet you, #{name}!"
> run
what is your name?
stephen
nice to meet you, stephen!
=> nil
> # but wouldn't it be nice if we printed the last line a few times?
=> nil
> 25 for _ in 0..5
> 35 end
> list
10 puts "what is your name?"
20 name = gets.chomp
25 for _ in 0..5
30 puts "nice to meet you, #{name}!"
35 end
> run
what is your name?
stephen
nice to meet you, stephen!
nice to meet you, stephen!
nice to meet you, stephen!
nice to meet you, stephen!
nice to meet you, stephen!
nice to meet you, stephen!
=> 0..5
> # but now our line numbers aren't equidistant anymore! let's clean them up
=> nil
> squish
> list
1 puts "what is your name?"
2 name = gets.chomp
3 for _ in 0..5
4 puts "nice to meet you, #{name}!"
5 end
> # or alternatively...
=> nil
> widen
> list
10 puts "what is your name?"
20 name = gets.chomp
30 for _ in 0..5
40 puts "nice to meet you, #{name}!"
50 end
> # alright, let's save our program
=> nil
> save greeter.rub
> # or if you just want a normal ruby file
=> nil
> export greeter.rb
> # with load/import you can also do the opposite (load an existing rub or rb file)
=> nil
Installation
Install the gem and add to the application's Gemfile by executing:
bundle add rubic-repl
If bundler is not being used to manage dependencies, install the gem by executing:
gem install rubic-repl
Usage
In your REPL or Ruby file, run Rubic::run
to start Rubic. Alternatively, run the CLI from your terminal with the rubic
command.
Development
After checking out the repo, run bin/setup
to install dependencies. Then, run rake test
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 the created tag, and push the .gem
file to rubygems.org.
Contributing
Bug reports and pull requests are welcome at https://gitlab.scd31.com/stephen/rubic
License
The gem is available as open source under the terms of the MIT License.