Class: Ripl::Shell
- Inherits:
-
Object
- Object
- Ripl::Shell
- Defined in:
- lib/ripl/shell.rb
Direct Known Subclasses
Constant Summary collapse
- OPTIONS =
{:name=>'ripl', :line=>1, :result_prompt=>'=> ', :prompt=>'>> ', :binding=>TOPLEVEL_BINDING, :irbrc=>'~/.irbrc', :history=>'~/.irb_history'}
Instance Attribute Summary collapse
-
#binding ⇒ Object
Returns the value of attribute binding.
-
#line ⇒ Object
Returns the value of attribute line.
-
#result_prompt ⇒ Object
Returns the value of attribute result_prompt.
Instance Method Summary collapse
- #format_error(e) ⇒ Object
- #format_result(result) ⇒ Object
- #get_input ⇒ Object
-
#initialize(options = {}) ⇒ Shell
constructor
A new instance of Shell.
- #loop ⇒ Object
- #loop_once(input) ⇒ Object
- #print_eval_error(e) ⇒ Object
Constructor Details
Instance Attribute Details
#binding ⇒ Object
Returns the value of attribute binding.
6 7 8 |
# File 'lib/ripl/shell.rb', line 6 def binding @binding end |
#line ⇒ Object
Returns the value of attribute line.
6 7 8 |
# File 'lib/ripl/shell.rb', line 6 def line @line end |
#result_prompt ⇒ Object
Returns the value of attribute result_prompt.
6 7 8 |
# File 'lib/ripl/shell.rb', line 6 def result_prompt @result_prompt end |
Instance Method Details
#format_error(e) ⇒ Object
43 44 45 |
# File 'lib/ripl/shell.rb', line 43 def format_error(e) "#{e.class}: #{e.}\n\t#{e.backtrace.join("\n\t")}" end |
#format_result(result) ⇒ Object
47 48 49 |
# File 'lib/ripl/shell.rb', line 47 def format_result(result) @options[:result_prompt] + result.inspect end |
#get_input ⇒ Object
23 24 25 26 |
# File 'lib/ripl/shell.rb', line 23 def get_input print @options[:prompt] $stdin.gets.chomp end |
#loop ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/ripl/shell.rb', line 13 def loop before_loop while true do input = get_input break if !input || input == 'exit' puts loop_once(input) end after_loop end |
#loop_once(input) ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/ripl/shell.rb', line 28 def loop_once(input) begin result = loop_eval(input) rescue Exception => e print_eval_error(e) end @line += 1 format_result result end |
#print_eval_error(e) ⇒ Object
39 40 41 |
# File 'lib/ripl/shell.rb', line 39 def print_eval_error(e) warn format_error(e) end |