's Blog

Look at the sky, it's so beautiful

Start IRB in Context of an Object

| Comments

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
require 'irb'
require 'irb/completion'

class Clazz
    def start_irb
  IRB.setup nil
  IRB.conf[:MAIN_CONTEXT] = IRB::Irb.new.context
  IRB.conf[:PROMPT_MODE] = :SIMPLE
  
  #puts this line outside this method will not work
  require 'irb/ext/multi-irb'

  #clear parameter
  ARGV.clear
  IRB.irb nil, self #<--- pass context
    end
end

Comments