14

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?

Phrogz
  • 296,393
  • 112
  • 651
  • 745
Spencer
  • 21,348
  • 34
  • 85
  • 121
  • 1
    For those that know Ruby but not Python, please explain what those lines do. – Phrogz Dec 01 '11 at 20:16
  • You should describe this code in plain english, in case we don't speak python – Damien Dec 01 '11 at 20:17
  • hese lines essentially insert a single breakpoint into my code and open up a console where I can interact with any variables. – Spencer Dec 01 '11 at 20:19

2 Answers2

16

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?

Community
  • 1
  • 1
Phrogz
  • 296,393
  • 112
  • 651
  • 745
1

There is Kernel#local_variables in Ruby that returns the names of the current local variables. Check out the docs:

ri local_variables
Marek Příhoda
  • 11,108
  • 3
  • 39
  • 53