Forum: Ruby Creating a method like Array(object)

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Farrel L. (Guest)
on 2006-05-11 12:03
(Received via mailing list)
Hi all,

Array has a nice feature where it can take an object and return an
array containing the object (or if the object is an Array returns the
object unchanged. So Array(1) is [1] but Array([1,2,3]) returns
[1,2,3]. I'd like to define a similar type of method for my own class
but have no idea how to define it. Is there a special function I must
define or is this an Array only specialty?

Farrel L. (Guest)
on 2006-05-11 12:06
(Received via mailing list)
Whoops! Never mind just realised Array() isn't a class it's a method on
This topic is locked and can not be replied to.