Module: Ripl::Shell::API
- Included in:
- Ripl::Shell
- Defined in:
- lib/ripl/shell.rb
Instance Method Summary collapse
- #after_loop ⇒ Object
- #before_loop ⇒ Object
- #during_loop ⇒ Object
- #format_error(err) ⇒ Object
- #format_result(result) ⇒ Object
- #get_input ⇒ Object
- #loop_eval(str) ⇒ Object
- #loop_once(input) ⇒ Object
- #print_eval_error(err) ⇒ Object
- #prompt ⇒ Object
Instance Method Details
#after_loop ⇒ Object
76 |
# File 'lib/ripl/shell.rb', line 76 def after_loop; end |
#before_loop ⇒ Object
29 30 31 |
# File 'lib/ripl/shell.rb', line 29 def before_loop Ripl::Runner.load_rc(@irbrc) if @irbrc end |
#during_loop ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/ripl/shell.rb', line 33 def during_loop while true do @error_raised = nil input = get_input break if !input || input == 'exit' loop_once(input) puts(format_result(@last_result)) unless @error_raised end end |
#format_error(err) ⇒ Object
70 |
# File 'lib/ripl/shell.rb', line 70 def format_error(err); Ripl::Runner.format_error(err); end |
#format_result(result) ⇒ Object
72 73 74 |
# File 'lib/ripl/shell.rb', line 72 def format_result(result) @options[:result_prompt] + result.inspect end |
#get_input ⇒ Object
43 44 45 46 |
# File 'lib/ripl/shell.rb', line 43 def get_input print prompt $stdin.gets.chomp end |
#loop_eval(str) ⇒ Object
62 63 64 |
# File 'lib/ripl/shell.rb', line 62 def loop_eval(str) eval(str, @binding, "(#{@name})", @line) end |
#loop_once(input) ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'lib/ripl/shell.rb', line 52 def loop_once(input) @last_result = loop_eval(input) eval("_ = Ripl.shell.last_result", @binding) rescue Exception => e @error_raised = true print_eval_error(e) ensure @line += 1 end |
#print_eval_error(err) ⇒ Object
66 67 68 |
# File 'lib/ripl/shell.rb', line 66 def print_eval_error(err) warn format_error(err) end |
#prompt ⇒ Object
48 49 50 |
# File 'lib/ripl/shell.rb', line 48 def prompt @options[:prompt].respond_to?(:call) ? @options[:prompt].call : @options[:prompt] end |