From: Stefano Crocco Date: 2008-05-22T03:59:37+09:00 Subject: Re: to_yaml method for array On Wednesday 21 May 2008, Raj Singh wrote: > This is irb. > > > irb > > irb(main):001:0> a = %w[ 1 2 3 ] > => ["1", "2", "3"] > irb(main):002:0> a.to_yaml > NoMethodError: undefined method `to_yaml' for ["1", "2", "3"]:Array > from (irb):2 > > > This is Rails script/console > > >> a = %w[ 1 2 3] > > => ["1", "2", "3"] > > >> a.to_yaml > > => "--- \n- \"1\"\n- \"2\"\n- \"3\"\n" > > > However no where in ActiveSupport I can find where Rails is implementing > the method to_yaml. > > I go to http://www.ruby-doc.org/core/ and look for Array methods. I see > to_yaml. So why in the irb I am getting undefined method to_yaml? You need to require 'yaml' before using the Array#to_yaml method (or any other predefined to_yaml methods, for the matter). I guess Rails console already does that itself, so there your code works. Regarding the documentation, unfortunately the one you mention mixes 'core' classes (that is, classes and modules which are always availlable) and 'standard library' classes (classes and modules which are distributed with ruby but need to be required to be used). The to_yaml method is defined in a file in the standard library, but that can't be guessed from the documentation. If you want to generate the documentation for only the core classes, you can follow the procedure explained in this thread: http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/294786 The documentation for only the standard library can be downloaded here: http://www.ruby-doc.org/stdlib/ I hope this helps Stefano