Module: Nanite::Console

Defined in:
lib/nanite/console.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.instanceObject

Returns the value of attribute instance.



16
17
18
# File 'lib/nanite/console.rb', line 16

def instance
  @instance
end

Class Method Details

.start(binding) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/nanite/console.rb', line 18

def self.start(binding)
  require 'irb'
  old_args = ARGV.dup
  ARGV.replace ["--simple-prompt"]

  IRB.setup(nil)
  self.instance = IRB::Irb.new(IRB::WorkSpace.new(binding))

  @CONF = IRB.instance_variable_get(:@CONF)
  @CONF[:IRB_RC].call self.instance.context if @CONF[:IRB_RC]
  @CONF[:MAIN_CONTEXT] = self.instance.context

  catch(:IRB_EXIT) { self.instance.eval_input }
ensure
  ARGV.replace old_args
  # Clean up tty settings in some evil, evil cases
  begin; catch(:IRB_EXIT) { irb_exit }; rescue Exception; end
  # Make nanite exit when irb does
  EM.stop if EM.reactor_running?
end