From: Dave Thomas Date: 2008-03-17T00:59:43+09:00 Subject: Re: argh! more undocumented mysteries: to_yaml On Mar 16, 2008, at 8:56 AM, Tom Cloyd wrote: > I'm exploring the wonders of the Object class, and I see > Object#to_yaml. Seems pretty obvious what to expect here, which > would seem to account for the total lack of documentation in each of > the gazillion instances of this method which appear in core library. > Still, let's test it... > > irb(main):010:0> [2,5,3,6,'abc'].to_yaml > NoMethodError: undefined method `to_yaml' for [2, 5, 3, 6, > "abc"]:Array > from (irb):10 > from :0 > > Can someone explain what just happened? Tom: Could you tell us just where you found the description of Object#to_yaml. As others have explained, to_yaml is not a built-in method. It is added when you require the yaml library. So, if a piece of documentation is out there that fails to make it clear that this library must be loaded before to_yaml is called, then that documentation needs to be fixed. As others have also pointed out, once the library is loaded, you can indeed invoke to_yaml on arrays, hashes, and so on. Regards Dave Thomas