Binding#irb Start a REPL session similar to binding.pry

22 Mar 2017 | category: ruby-2.4.0 | Comments
#ruby #tech

Ruby 2.4.0 introduced new feature for debugging

While you are debugging, you may often use p to see the value of variables. With pry you can use binding.pry in your application to launch a REPL and run any Ruby code. Ruby 2.4.0 introduces binding.irb which behaves like that with irb.


  irb(main):001:0> def test_irb
  irb(main):002:1>   p 'before irb'
  irb(main):003:1>   binding.irb
  irb(main):004:1>   p 'after irb'
  irb(main):005:1> end
  => :test_irb
  irb(main):006:0> test_irb
  "before irb"
  irb(main):001:0> exit
  "after irb"
  => "after irb"
  irb(main):007:0>