Search code examples
pythonruby-on-railsrubydebuggingbreakpoints

Drop in Single Breakpoint in Ruby Code


I am trying to find ruby code that has commensurate functionality to these lines in python:

import code
code.interact(local=locals())

These lines essentially insert a single breakpoint into my code and open up a console where I can interact with any variables.

Any thoughts on how to do this in Ruby?


Solution

  • You want the Pry library:

    require 'pry' # gem install pry
    binding.pry   # Drop into the pry console
    

    Read more here:
    http://banisterfiend.wordpress.com/2011/01/27/turning-irb-on-its-head-with-pry/

    See also:
    How to use Pry with Sinatra?