From: Jason Roelofs Date: 2008-05-08T21:50:25+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") > ^ > > > Any reason for this? It seems that << is a littled "hardcoded", isn't? > > -- > Iņaki Baz Castillo > > The << operator is a special case handled by the parser, but you can bypass that handling by calling the method directly: my_array.<<("Header", "Value") which will of course look a ton better by just using a custom method: my_array.add_stuff "Header", "Value" Jason R.