Class: Ripl::Shell

Inherits:
Object
  • Object
show all
Includes:
API
Defined in:
lib/ripl/shell.rb

Defined Under Namespace

Modules: API

Constant Summary collapse

OPTIONS =
{:name=>'ripl', :result_prompt=>'=> ', :prompt=>'>> ',
:binding=>TOPLEVEL_BINDING, :irbrc=>'~/.irbrc'}
EXIT_WORDS =
[nil, 'exit', 'quit']

Instance Attribute Summary collapse

Attributes included from API

#prompt, #result_prompt

Class Method Summary collapse

Instance Method Summary collapse

Methods included from API

#add_commands, #after_loop, #before_loop, #eval_input, #format_error, #format_result, #get_input, #handle_interrupt, #loop_eval, #loop_once, #print_eval_error, #print_result

Constructor Details

#initialize(options = {}) ⇒ Shell

Returns a new instance of Shell.



15
16
17
18
19
20
# File 'lib/ripl/shell.rb', line 15

def initialize(options={})
  options = OPTIONS.merge options
  @name, @binding = options.values_at(:name, :binding)
  @prompt, @result_prompt = options.values_at(:prompt, :result_prompt)
  @irbrc, @line = options[:irbrc], 1
end

Instance Attribute Details

#bindingObject

Returns the value of attribute binding.



14
15
16
# File 'lib/ripl/shell.rb', line 14

def binding
  @binding
end

#lineObject

Returns the value of attribute line.



14
15
16
# File 'lib/ripl/shell.rb', line 14

def line
  @line
end

#nameObject

Returns the value of attribute name.



14
15
16
# File 'lib/ripl/shell.rb', line 14

def name
  @name
end

#resultObject

Returns the value of attribute result.



14
15
16
# File 'lib/ripl/shell.rb', line 14

def result
  @result
end

Class Method Details

.create(options = {}) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/ripl/shell.rb', line 6

def self.create(options={})
  require 'ripl/readline' if options[:readline]
  require 'ripl/completion'
  new(options)
rescue LoadError
  new(options)
end

Instance Method Details

#configObject



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

def config; Ripl.config; end

#loopObject

Loops shell until user exits



23
24
25
26
27
# File 'lib/ripl/shell.rb', line 23

def loop
  before_loop
  catch(:ripl_exit) { while(true) do; loop_once; end }
  after_loop
end