I'm trying to learn how to step through Ruby code (written by more experienced programmers) in order to improve my knowledge of Ruby. Problem is that I don't really know how to do it well. Googling the topic brought me to an about.com page on Ruby; I thought a higher quality more comprehensive answer should belong on StackOverflow, so if anyone can write an answer (with an example) for it, showing how a beginner can step through code to learn as much as possible about it, it'd be much appreciated.
closed as off topic by Walter, Yusubov, MainMa, GlenH7, Yannis♦ Oct 22 '12 at 18:42Questions on Programmers Stack Exchange are expected to relate to software development within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here. If this question can be reworded to fit the rules in the help center, please edit the question. |
|||||||||||||||||||||
|
What you're looking for is a debugger. With ruby 1.8, the Start your program with the gem loaded, for example The debugger kicks in at a breakpoint, which is a signal to suspend execution, and give you a chance to poke around. Typically, the easiest way to set a breakpoint is to add a source line at the point in execution you're interested in. Inserting a call to
Lets launch it:
The program starts executing, then the debugger breaks us at line four. It shows us the next statement which is to be executed next. We can get a more complete listing of our surroundings by typing
You can examine the result of expressions by using the
The debugger has has interactive help which can be accessed with |
|||
|