IRB Anywhere

IRB, short for Interactive RuBy, is a very useful ruby shell. Just run "irb" and you'll end up in a interactive ruby session. This comes in very handy for running various snippets of code to make sure they do what you intend. But what if you want to run IRB in the middle of a running program, so you can interact with it?

Turns out this is very simple:

#irbtest.rb

require 'irb'

some_var = 1
SOME_CONST = "hello"
puts "before irb"

IRB.start

puts "after irb"
puts some_var
puts SOME_CONST