I’m trying to use y object in Rails 3.2.6/Ruby 1.9.3 console to get nicely formatted yaml output for an ActiveRecord object, but for some reason it isn’t working for me. I’ve used it in the past, but somewhere along the way it broke. I get the following output when I try:
NameError: undefined local variable or method `yaml' for main:Object
The
ymethod is actually an extension to theKernelobject put in place by the Syck YAML parser/emitter. Here are the last few lines oflib/ruby/1.9.1/syck.rb:By default, Ruby 1.9.3 uses the Psych parser/emitter instead of Syck (I can only presume they’re pronounced differently), and Psych doesn’t declare such a method.
If you really loved
y, you can simply use Syck instead of Psych in the console:I’ll also use this chance to plug awesome_print, which does for basically everything what
ydoes for YAML.