Ruby 2.4 Binding#irb

Hello! Ruby2.4.0.preview3 was released yesterday. There are some really cool features in it. I will mention one of these. It is about debugging or open a REPL session. As you know before that release, Ruby developers use p or other lovely gem pry to debug. For now binding#irb provides to debug in your application.

First, we need to install latest Ruby version. We can do it via RVM.

$ rvm install 2.4.0-preview3

Don’t forget to select the right version.

$ rvm use 2.4.0-preview3

Now we can test that feature with a small Ruby program.

require 'irb'

class Test
  def self.hello(name)
    binding.irb
    puts "Hello #{name}"
  end
end

puts Test.hello('ender')
> ruby ruby24p3.rb
2.4.0-preview3 :001 > name
#=> "ender"

That’s it. After Ruby 2.4 we won’t need to write p we can open a REPL in anytime.

Cheers.

comments powered by Disqus