Skip to content

End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

instance method

Kernel#Array

Array(arg) → array

Returns arg as an Array.

First tries to call to_ary on arg, then to_a. If arg does not respond to to_ary or to_a, returns an Array of length 1 containing arg.

If to_ary or to_a returns something other than an Array, raises a TypeError.

Example
Array(["a", "b"])  #=> ["a", "b"]
Array(1..5)        #=> [1, 2, 3, 4, 5]
Array(key: :value) #=> [[:key, :value]]
Array(nil)         #=> []
Array(1)           #=> [1]
See also #abort #at_exit #` #autoload also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.1