From: Gary Wright Date: 2007-02-08T06:58:58+09:00 Subject: Re: Defining << On Feb 7, 2007, at 4:46 PM, Luke Ivers wrote: > I'm not 100% how exactly to search to find out if someone else has > posed > this question, but why does the following happen? > > Given: > > class Hash > def << (key, val=nil) > self.store(key, val) > end > end > > h = {} > h << 'test' > h << 'test', 'bob' The syntax rules for the << operator don't allow it to take multiple arguments when called via infix notation: h << arg1 # one argument only you can call the method with multiple arguments but you've got to do it like: h.<<(arg1, arg2) # dot-style method invocation You can use an array to 'cheat': h << [arg1, arg2] But the method will only see one argument, an array, and you would have to expect that and/or test for it in your definition for Hash#<<. Gary Wright