Forum: Ruby Creating a method like Array(object)

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
05be5d6610e2c3f1780aa0e39e902e93?d=identicon&s=25 Farrel Lifson (Guest)
on 2006-05-11 10: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
05be5d6610e2c3f1780aa0e39e902e93?d=identicon&s=25 Farrel Lifson (Guest)
on 2006-05-11 10:06
(Received via mailing list)
Whoops! Never mind just realised Array() isn't a class it's a method on
Kernel.
This topic is locked and can not be replied to.