From: Daniel Baird Date: 2006-06-27T09:03:30+09:00 Subject: Re: << for Hash? ------=_Part_1330_2881756.1151366547752 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline On 6/27/06, Simon Baird wrote: > > On 6/26/06, Matthew Harris wrote: > > > I like Michael's solution. > > > > The {}'s are not needed, as long as the hash is the only or last > > argument to a method. > > > > {:a => 1, :b => 2}.merge(:c => 3, :d => 4) > > #=> {:a => 1, :b => 2, :c => 3, :d => 4) > > > I noticed this: > > class Hash > def <<(arg) > self.merge!(arg) > end > end > > x = { :a => 1 } > > x.<< :f => 1, :g => 1 # works > > x << :h => 1, :i => 1 # syntax error > > Is there a way to make the above work? I don't care really since I think > the > following is clearer: > x << { :h => 1, :i => 1 } # my preferred No, sorry.. as pointed out in another recent thread, overriding the << method can change the behaviour but not the syntax of the << operator. Curses, huh. ;D -- Daniel Baird http://danielbaird.com (TiddlyW;nks! :: Whiteboard Koala :: Blog :: Things That Suck) ------=_Part_1330_2881756.1151366547752--