Rails Recipes Book: Authentication

Define this method in a module. Then do a "require" in a superclass
and now you can use it in any of the sub-classes without explicit
require statement.

I put this in a utilities.db file while I'm debugging:

require 'pp'

def dbg *args
  if ENV['RAILS_ENV'] == 'test'
    stack = caller(1).slice(0, 4)
    $stdout << "==========================\n"
    pp stack
    def dbg(*args)

I'll frequently change the slice size for the stack trace (0 to large)
depending on what I'm doing, or add little snippets of code to do particular
things with args. I think of it more like a debugger macro than actual

Defining dbg (or whatever you want to call it) for all objects means you
don't have to put in include statements, making it slightly easier to remove
when you're no longer debugging.

I usually don't use the logger for debugging printf. Most of the time I
want to see those debug statements on stdout/stderr when I'm running tests,
and if I'm not running tests I don't care about them.

- James Moore