Class: WebConsole::REPL::IRB

Inherits:
Object
  • Object
show all
Defined in:
lib/web_console/repl/irb.rb

Overview

IRB\ Adapter

Adapter for the IRB REPL, which is the default Ruby on Rails console.

Defined Under Namespace

Classes: FiberInputMethod

Instance Method Summary collapse

Constructor Details

#initialize(binding = TOPLEVEL_BINDING) ⇒ IRB

Returns a new instance of IRB.



27
28
29
30
31
32
33
# File 'lib/web_console/repl/irb.rb', line 27

def initialize(binding = TOPLEVEL_BINDING)
  initialize_irb_session!
  @input = FiberInputMethod.new
  @irb   = ::IRB::Irb.new(::IRB::WorkSpace.new(binding), @input)
  @fiber = Fiber.new { @irb.eval_input }.tap(&:resume)
  finalize_irb_session!
end

Instance Method Details

#promptObject



35
36
37
# File 'lib/web_console/repl/irb.rb', line 35

def prompt
  @input.prompt
end

#send_input(input) ⇒ Object



39
40
41
# File 'lib/web_console/repl/irb.rb', line 39

def send_input(input)
  Stream.threadsafe_capture! { @fiber.resume("#{input}\n") }
end