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

Written byRohit Arolkar
Related blogs
- 01Ruby 2.4 has optimized enumerable min max methodsSeptember 28, 2017 · Chirag Shah
- 02CSV::Row#each etc. return enumerator when no block givenSeptember 25, 2017 · Sushant Mittal
- 03Ruby 2.4 DateTime#to_time & Time#to_time keeps infoSeptember 19, 2017 · Sushant Mittal
- 04Avoid exception for dup on IntegerAugust 1, 2017 · Rohit Arolkar