Module: IRB

Defined in:
lib/bombshell/irb.rb

Overview

We have to monkey patch a method into IRB here. I've tried extending it, and it doesn't work.

Class Method Summary collapse

Class Method Details

.start_session(binding) ⇒ Object

Launch a custom IRB session with the given binding, set up the prompt, and define tab completion.

Parameters:

  • binding (Binding)

    Your shell's binding



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/bombshell/irb.rb', line 7

def self.start_session(binding)
  unless @__initialized
    args = ARGV
    ARGV.replace(ARGV.dup)
    IRB.setup(nil)
    ARGV.replace(args)
    @__initialized = true
  end

  workspace = WorkSpace.new(binding)
  
  @CONF[:PROMPT][:BOMBSHELL] = {
    :PROMPT_I => "%m> ",
    :PROMPT_S => "%m\"> ",
    :PROMPT_C => "%m…>",
    :PROMPT_N => "%m→>",
    :RETURN => ''
  }
  @CONF[:PROMPT_MODE] = :BOMBSHELL

  irb = Irb.new(workspace)

  ::Readline.completion_proc = Bombshell::Completor.new(eval('self.class', binding)).method(:complete)
  
  @CONF[:IRB_RC].call(irb.context) if @CONF[:IRB_RC]
  @CONF[:MAIN_CONTEXT] = irb.context
  catch(:IRB_EXIT) do
    irb.eval_input
  end
end