From: Robert Klemme Date: 2009-01-17T19:03:52+09:00 Subject: Re: Defining an object constructor that look like [] or {} ...? On 16.01.2009 20:15, Sonny Chee wrote: > Ruby has built in object constuctors for Array and Hash via [] and {}.. > ie: > > an_array = [1, 2, 3, 6] > a_hash = {1=>3, 2=>5, 'a'=>'green'} > > I would like to do the same for one of my classes.. i.e. > > my_object = |2, 3, 5, 7| > > should yield the same result as if I had done the following: > > my_object = MyClass.new([2, 3, 5, 7]) > > Is this possible? No, because you would have to change Ruby's syntax. See the other postings for alternatives. Kind regards robert -- remember.guy do |as, often| as.you_can - without end