How can I do this in Ruby?:
Sometimes for diagnostics in interpreted language, it’s faster for me to make a quick alteration to my code, tossing an object into the top-level namespace, then mess with it there in an interactive environment.
In Python, I add this to my code:
import __main__
__main__.[field] = [my problematic object]
…then run the file with a command python -i [myfilename]. Any idea how I can get access to the top-level namespace in Ruby?
I’d recommend using Pry for this.
Run
gem install pryto install pry. Then add the following code where you want to start an interactive session.An example of an interactive session.