public Method

Object.to_a

obj.to_a  anArray

Returns an array representation of obj. For objects of class Object and others that don’t explicitly override the method, the return value is an array containing self. However, this latter behavior will soon be obsolete.

self.to_a       #=> -:1: warning: default `to_a' will be obsolete
"hello".to_a    #=> ["hello"]
Time.new.to_a   #=> [39, 54, 8, 9, 4, 2003, 3, 99, true, "CDT"]

Source Code

/*
*  call-seq:
*     obj.to_a -> anArray
*  
*  Returns an array representation of <i>obj</i>. For objects of class
*  <code>Object</code> and others that don't explicitly override the
*  method, the return value is an array containing <code>self</code>. 
*  However, this latter behavior will soon be obsolete.
*     
*     self.to_a       #=> -:1: warning: default `to_a' will be obsolete
*     "hello".to_a    #=> ["hello"]
*     Time.new.to_a   #=> [39, 54, 8, 9, 4, 2003, 3, 99, true, "CDT"]
*/


static VALUE
rb_any_to_a(obj)
   VALUE obj;
{
   rb_warn("default `to_a' will be obsolete");
   return rb_ary_new3(1, obj);
}
Comments

Have your say
Please use Textile formatting (click here for a cheat sheet). Use <code/> and <pre/> for code samples.
Click here to login with OpenID to to post comments.