Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

This ripl plugin allows you to evaluate multiple lines of code.

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 test
Octocat-spinner-32 .gitignore
Octocat-spinner-32 .travis.yml
Octocat-spinner-32 CHANGELOG.rdoc
Octocat-spinner-32 LICENSE.txt
Octocat-spinner-32 README.rdoc
Octocat-spinner-32 Rakefile
Octocat-spinner-32 ripl-multi_line.gemspec
README.rdoc

ripl-multi_line

This ripl plugin allows you to evaluate multiple lines of Ruby code.

Install

Install the gem with

gem install ripl-multi_line

Usage

Add the following line to your ~/.riplrc

require 'ripl/multi_line'

Hint: In multi-line situations, you can press ctrl+c and the last line will be removed.

Options

You can customize your multi-line prompt with the :multi_line_prompt option. For example, put this into your ~/.riplrc:

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.

AutoIndent

Check out the ripl-auto_indent plugin to get ruby syntax indention.

MultiLine detection

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 Ripl.config[:multi_line_engine] to :your_correct_detection. See 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 ;)

Troubleshooting

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

TODO

  • Write thousands of test cases

J-_-L

Contributions & influences by cldwalker and godfat.

Something went wrong with that request. Please try again.