Module: Ripl::Shell::API

Included in:
Ripl::Shell
Defined in:
lib/ripl/shell.rb

Instance Method Summary collapse

Instance Method Details

#after_loopObject

Called after shell finishes looping.



96
# File 'lib/ripl/shell.rb', line 96

def after_loop; end

#before_loopObject

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

Parameters:

  • (Exception)

Returns:

  • (String)


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.

Returns:

  • (String)

    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_inputString?

Returns Prints #prompt and returns input given by user.

Returns:

  • (String, nil)

    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

Prints error formatted by #format_error to STDERR. Could be extended to handle certain exceptions.

Parameters:

  • (Exception)


76
77
78
# File 'lib/ripl/shell.rb', line 76

def print_eval_error(err)
  warn format_error(err)
end

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

#promptString

Returns:

  • (String)


64
65
66
# File 'lib/ripl/shell.rb', line 64

def prompt
  @prompt.respond_to?(:call) ? @prompt.call : @prompt
end