From: Michael Fellinger Date: 2006-06-26T15:34:55+09:00 Subject: Re: << for Hash? {:foo,1}.merge! :bar => 2 # {:foo=>1, :bar=>2} On Monday 26 June 2006 13:11, Simon Baird wrote: > class Hash > def <<(arg) > self.merge!(arg) > end > end > > Eg, > > thing = { > > :foo => 1, > > } > > thing << { > > :bar => 2, > : > :baz => 3, > > } > > thing #=> {:foo=>1, :bar=>2, :baz=>3 } > > > Of course it overwrites existing keys. I think it's a little sexier than > > thing.merge!({ > > :bar => 2, > :baz => 3, > > }) > > or > thing[:bar] = 1 > thing[:baz] = 3 > > > Is it safe to use this? Is there some good reason why << is not already > defined for Hash? > > Simon > (newbie) > > Ps, my first ruby project: > http://tiddlyspot.com/