From: "Iñaki Baz Castillo" Date: 2008-05-08T22:31:30+09:00 Subject: Re: Why can't I redefine "<<" method to allow two parameters? 2008/5/8, Jens Wille : > Jason Roelofs [2008-05-08 14:50]: > > > On Thu, May 8, 2008 at 8:42 AM, Iñaki Baz Castillo wrote: > the point is that you can't call an operator with multiple > arguments. maybe something like this will suit you (note that you > don't need to alias if you inherit from Array): > > class MyArray < Array > def <<(*a) > a = [*(a=*a)] # a.to_a.flatten_once ;-) > raise ArgumentError, "wrong number of arguments (#{a.size} for > 2)" if a.size != 2 > > super a.join(': ') > > end > end > > my_array = MyArray.new > > my_array << ['Header1', 'Value1'] # => ["Header1: Value1"] > my_array.<<('Header2', 'Value2') # => ["Header1: Value1", > "Header2: Value2"] Thanks to all. Finally I'll just create a "add" method that will call internally to << method using appropiate syntax: self.<< (k, v) Thanks. -- Iñaki Baz Castillo