Put -r debug (the space is optional; -rdebug works too) on the Ruby command line with a script name, and you get access to lots of diagnostic tools, making it unnecessary to sprinkle your code with diagnostic messages.
The debugger gives you what amounts to an intelligent pause control, letting you freeze a script's execution and examine the contents of variables at any time. How that pause control is invoked can vary depending on your needs.
Any time you're in the debugger, you can enter an h (for help) command to get a list, like the following, of all the things you can do there.
~/testcode:>ruby -r debug div0.rb Debug.rb Emacs support available. div0.rb:3:def foo (rdb:1) h Debugger help v.-0.002b Commands b[reak] [file|method:]<line|method> ...