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?
To help deal with bugs, the standard distribution of Ruby includes a debugger. In order to start the Ruby debugger, load the debug library using the command-line option -r debug. The debugger stops before the first line of executable code and asks for the input of user commands.
wherever you'd like the application to "break" - that is, executing byebug is equivalent to putting a breakpoint in your code. Run the program and use the debugger commands once you reach the breakpoint. near the end. Restart your server.
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?
There is Kernel#local_variables in Ruby that returns the names of the current local variables. Check out the docs:
ri local_variables
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With