Skip to content
instance method

Array#to_a

() -> ::Array[Elem]
to_a → self or new_array

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.

See also #take_while #to_ary #take #to_h also in 4.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0