Binding irb - Runtime Invocation for IRB

This blog is part of our  Ruby 2.4 series.

It's very common to see a ruby programmer write a few puts or p statements, either for debugging or for knowing the value of variables.

pry did make our lives easier with the usage of binding.pry. However, it was still a bit of an inconvenience to have it installed at runtime, while working with the irb.

Ruby 2.4 has now introduced binding.irb. By simply adding binding.irb to our code we can open an IRB session.


class ConvolutedProcess
def do_something
@variable = 10

    binding.irb
    # opens a REPL here

end
end

irb(main):029:0\* ConvolutedProcess.new.do_something
irb(#<ConvolutedProcess:0x007fc55c827f48>):001:0> @variable
=> 10

Related blogs

Follow @bigbinary on X. Check out our full blog archive.