End of Life Ruby 3.2 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
Kernel#Array
Array(object) → object or new_array
object.c
View on GitHub ↗
static VALUE
rb_f_array(VALUE obj, VALUE arg)
{
return rb_Array(arg);
}
Returns an array converted from object.
Tries to convert object to an array using to_ary first and to_a second:
Example
Array([0, 1, 2]) # => [0, 1, 2] Array({foo: 0, bar: 1}) # => [[:foo, 0], [:bar, 1]] Array(0..4) # => [0, 1, 2, 3, 4]
Returns object in an array, [object], if object cannot be converted:
Example
Array(:foo) # => [:foo]