Module: Ripl::Shell::API
- Included in:
- Ripl::Shell
- Defined in:
- lib/ripl/shell.rb
Instance Method Summary collapse
-
#after_loop ⇒ Object
Called after shell finishes looping.
-
#before_loop ⇒ Object
Sets up shell before looping by loading ~/.irbrc.
-
#format_error(err) ⇒ String
Formats errors raised by eval of user input.
-
#format_result(result) ⇒ String
Formats result using result_prompt.
-
#get_input ⇒ String?
Prints #prompt and returns input given by user.
-
#loop_eval(str) ⇒ Object
Evals user input using @binding, @name and @line.
-
#print_eval_error(err) ⇒ Object
Prints error formatted by #format_error to STDERR.
-
#print_result(result) ⇒ Object
Prints result using #format_result.
- #prompt ⇒ String
Instance Method Details
#after_loop ⇒ Object
Called after shell finishes looping.
96 |
# File 'lib/ripl/shell.rb', line 96 def after_loop; end |
#before_loop ⇒ Object
Sets up shell before looping by loading ~/.irbrc. Can be extended to initialize plugins and their instance variables.
53 54 55 |
# File 'lib/ripl/shell.rb', line 53 def before_loop Ripl::Runner.load_rc(@irbrc) if @irbrc end |
#format_error(err) ⇒ String
Formats errors raised by eval of user input
88 |
# File 'lib/ripl/shell.rb', line 88 def format_error(err); Ripl::Runner.format_error(err); end |
#format_result(result) ⇒ String
Returns Formats result using result_prompt.
91 92 93 |
# File 'lib/ripl/shell.rb', line 91 def format_result(result) @result_prompt + result.inspect end |
#get_input ⇒ String?
Returns Prints #prompt and returns input given by user.
58 59 60 61 |
# File 'lib/ripl/shell.rb', line 58 def get_input print prompt $stdin.gets.chomp end |
#loop_eval(str) ⇒ Object
Evals user input using @binding, @name and @line
69 70 71 |
# File 'lib/ripl/shell.rb', line 69 def loop_eval(str) eval(str, @binding, "(#{@name})", @line) end |
#print_eval_error(err) ⇒ Object
Prints error formatted by #format_error to STDERR. Could be extended to handle certain exceptions.
76 77 78 |
# File 'lib/ripl/shell.rb', line 76 def print_eval_error(err) warn format_error(err) end |
#print_result(result) ⇒ Object
Prints result using #format_result
81 82 83 |
# File 'lib/ripl/shell.rb', line 81 def print_result(result) puts(format_result(result)) unless @error_raised end |
#prompt ⇒ String
64 65 66 |
# File 'lib/ripl/shell.rb', line 64 def prompt @prompt.respond_to?(:call) ? @prompt.call : @prompt end |