# Creating a method like Array(object)

**URL:** <https://www.ruby-forum.com/t/creating-a-method-like-array-object/60225>\
**Category:** Ruby\
**Created:** [May 11, 2006, 10:03am UTC](https://www.ruby-forum.com/t/creating-a-method-like-array-object/60225 "2006-05-11T10:03:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Farrel\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/9d8465/32.png) [@Farrel\_L](https://www.ruby-forum.com/u/Farrel_L)\
**Post date:** [May 11, 2006, 10:03am UTC](https://www.ruby-forum.com/t/creating-a-method-like-array-object/60225/1 "2006-05-11T10:03:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Farrel\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/9d8465/32.png) [@Farrel\_L](https://www.ruby-forum.com/u/Farrel_L)\
**Post date:** [May 11, 2006, 10:06am UTC](https://www.ruby-forum.com/t/creating-a-method-like-array-object/60225/2 "2006-05-11T10:06:19Z")

</div>

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