Class: Ripl::Shell
Defined Under Namespace
Modules: API
Constant Summary collapse
- OPTIONS =
{:name=>'ripl', :result_prompt=>'=> ', :prompt=>'>> ', :binding=>TOPLEVEL_BINDING, :irbrc=>'~/.irbrc'}
Instance Attribute Summary collapse
-
#binding ⇒ Object
Returns the value of attribute binding.
-
#line ⇒ Object
Returns the value of attribute line.
-
#name ⇒ Object
Returns the value of attribute name.
-
#result ⇒ Object
Returns the value of attribute result.
-
#result_prompt ⇒ Object
Returns the value of attribute result_prompt.
Class Method Summary collapse
Instance Method Summary collapse
- #config ⇒ Object
-
#eval_input(input) ⇒ Object
Sets @result to result of evaling input and print unexpected errors.
-
#initialize(options = {}) ⇒ Shell
constructor
A new instance of Shell.
-
#loop ⇒ Object
Loops shell until user exits.
-
#loop_once ⇒ Object
Runs through one loop iteration: gets input, evals and prints result.
Methods included from API
#after_loop, #before_loop, #format_error, #format_result, #get_input, #loop_eval, #print_eval_error, #print_result, #prompt
Constructor Details
Instance Attribute Details
#binding ⇒ Object
Returns the value of attribute binding.
13 14 15 |
# File 'lib/ripl/shell.rb', line 13 def binding @binding end |
#line ⇒ Object
Returns the value of attribute line.
13 14 15 |
# File 'lib/ripl/shell.rb', line 13 def line @line end |
#name ⇒ Object
Returns the value of attribute name.
13 14 15 |
# File 'lib/ripl/shell.rb', line 13 def name @name end |
#result ⇒ Object
Returns the value of attribute result.
13 14 15 |
# File 'lib/ripl/shell.rb', line 13 def result @result end |
#result_prompt ⇒ Object
Returns the value of attribute result_prompt.
13 14 15 |
# File 'lib/ripl/shell.rb', line 13 def result_prompt @result_prompt end |
Class Method Details
.create(options = {}) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/ripl/shell.rb', line 5 def self.create(={}) require 'ripl/readline' if [:readline] require 'ripl/completion' new() rescue LoadError new() end |
Instance Method Details
#eval_input(input) ⇒ Object
Sets @result to result of evaling input and print unexpected errors
40 41 42 43 44 45 46 47 48 |
# File 'lib/ripl/shell.rb', line 40 def eval_input(input) @result = loop_eval(input) eval("_ = Ripl.shell.result", @binding) rescue Exception => e @error_raised = true print_eval_error(e) ensure @line += 1 end |
#loop ⇒ Object
Loops shell until user exits
22 23 24 25 26 |
# File 'lib/ripl/shell.rb', line 22 def loop before_loop catch(:ripl_exit) { while(true) do; loop_once; end } after_loop end |
#loop_once ⇒ Object
Runs through one loop iteration: gets input, evals and prints result
31 32 33 34 35 36 37 |
# File 'lib/ripl/shell.rb', line 31 def loop_once @error_raised = nil @input = get_input throw(:ripl_exit) if !@input || @input == 'exit' eval_input(@input) print_result(@result) end |