Creating a method like Array(object)

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?


Whoops! Never mind just realised Array() isn’t a class it’s a method on

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs