This ripl plugin allows you to evaluate multiple lines of Ruby code.
Install the gem with
gem install ripl-multi_line
Add the following line to your
Hint: In multi-line situations, you can press
ctrl+c and the last line will be removed.
You can customize your multi-line prompt with the
:multi_line_prompt option. For example, put this into your
Ripl.config[:multi_line_prompt] = ' > '
It also takes a proc as value.
Then there is the
:multi_line_history option. The default value is
:compact which tries to squeeze your last multi-line block into one line (works best in mri, in about 98% of all cases).
>> def some_multi_line_block | 42 | end #=> nil # Press <UP> >> def some_multi_line_block; 42; end
Another value is
:block, which joins the multi-line block with new-lines.
To leave the history untouched, set it to
:plain or a false value.
Check out the ripl-auto_indent plugin to get ruby syntax indention.
To use your own multi-line detection engine, implement your version at
lib/ripl/multi_line/your_correct_detection.rb in which you overwrite
Shell#multiline? in a
Ripl::MultiLine sub-module named
YourCorrectDetection and set
lib/ripl/multi_line/*.rb for examples.
Currently available engines:
:live_error(default) - Simply evaluate expression, if it throws a multi-line syntax error, fall back to multi-line input mode. Sounds scary, but works pretty well in practice.
:error_check- Same principle as :live_error, but don't do it live
:ripper- Analyze input with Ripper (comes with 1.9, but there is also a 1.8 gem).
:ruby_parser- Use ruby_parser gem (1.8 only)
:irb- You left irb, but you are still used to its multi-line behaviour? Use irb's RubyLex!
None of the above solutions is perfect, so… maybe it's time to roll your own ;)
Problem: “I've required
ripl-multi_line, but it doesn't work”
Answer: This is probably caused by a plugin, which overwrites
:before_loop, but does not call
super (or you are using ripl-profiles older than 0.2.0). You can manually work around this issue with this snippet (but you should fix the general problem):
require 'ripl/multi_line/live_error.rb' Ripl::MultiLine.engine = Ripl::MultiLine::LiveError Ripl::Shell.include Ripl::MultiLine.engine
Write thousands of test cases
Contributions & influences by cldwalker and godfat.