Skip to content

Maintenance Ruby 3.3 gets fixes, but no new features. Switch to Ruby 4.0 →

class method

Array.try_convert

Array.try_convert(object) → object, new_array, or nil

If object is an Array object, returns object.

Otherwise if object responds to :to_ary, calls object.to_ary and returns the result.

Returns nil if object does not respond to :to_ary

Raises an exception unless object.to_ary returns an Array object.

See also .new #& .[] #* also in 4.1 · 4.0 · 3.4 · 3.2 · 3.1 · 3.0