From: Rick DeNatale Date: 2008-05-08T21:58:15+09:00 Subject: Re: Why can't I redefine "<<" method to allow two parameters? On Thu, May 8, 2008 at 8:42 AM, Iņaki Baz Castillo wrote: > Hi, very exrtange: > > > class MyArray < Array > alias original_add << > def <<(n,k) > original_add "#{n}: #{k}" > end > end > > my_array = MyArray.new > => [] > > my_array << ("Header", "Value") > > SyntaxError: compile error > (irb):25: syntax error, unexpected ',', expecting ')' > my_array << ("Header", "Value") The parser sees the << OPERATOR as taking a left and right argument, and turns that into a message send to the left argument. If you want to use additional arguments you need to be a bit more explicit and use a little less syntactic sugar: my_array.<<("Header","Value") # => ["Header: Value"] -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/