https://github.com/janlelis/ripl-multi_line
This ripl plugin allows you to evaluate multiple lines of code.
https://github.com/janlelis/ripl-multi_line
ripl ruby
Last synced: about 1 year ago
JSON representation
This ripl plugin allows you to evaluate multiple lines of code.
- Host: GitHub
- URL: https://github.com/janlelis/ripl-multi_line
- Owner: janlelis
- License: mit
- Created: 2010-11-09T11:19:16.000Z (over 15 years ago)
- Default Branch: master
- Last Pushed: 2013-04-23T12:02:19.000Z (about 13 years ago)
- Last Synced: 2025-03-27T09:45:36.246Z (about 1 year ago)
- Topics: ripl, ruby
- Language: Ruby
- Homepage:
- Size: 1.18 MB
- Stars: 6
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.rdoc
- Changelog: CHANGELOG.rdoc
- License: LICENSE.txt
Awesome Lists containing this project
README
== ripl-multi_line {
}[https://travis-ci.org/janlelis/ripl-multi_line]
This {ripl}[https://github.com/cldwalker/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
>> 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}[https://github.com/janlelis/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.