instance method
Array#to_a
() -> ::Array[Elem]
to_a → self or new_array
array.c
View on GitHub ↗
static VALUE
rb_ary_to_a(VALUE ary)
{
if (rb_obj_class(ary) != rb_cArray) {
VALUE dup = rb_ary_new2(RARRAY_LEN(ary));
rb_ary_replace(dup, ary);
return dup;
}
return ary;
}
When self is an instance of Array, returns self.
Otherwise, returns a new array containing the elements of self:
Example
class MyArray < Array; end my_a = MyArray.new(['foo', 'bar', 'two']) a = my_a.to_a a # => ["foo", "bar", "two"] a.class # => Array # Not MyArray.
Related: see Methods for Converting.