Saturday, January 05, 2008

Ruby pretty_print gotcha




I just ran into a tricky little error message today when trying to just "pp" (pretty print) a variable in Ruby. It took me a little digging, but I found that pp.rb had added a callback that looked for a method called "pretty_print" in my class. The error message looked like:


ArgumentError: wrong number of arguments (1 for 0)
/usr/lib/ruby/1.8/pp.rb:140:in `pretty_print'


with a long stack trace after it.

So, don't call your pretty print routines "pretty_print" if you want to be able to use "pp".