From: Trans Date: 2006-10-25T01:10:10+09:00 Subject: Re: '**' as hash splat? Ken Bloom wrote: > On Mon, 23 Oct 2006 20:49:55 -0700, Trans wrote: > > > We can: > > > > a = [2,1] > > [3,*a] #=> [3,2,1] > > > > How about: > > > > h = {:b=>2, :a=>1} > > {:c => 3, **h} #=> {:c=>3, :b=>2, :a=>1} > > > > T. > > The purpose of splat is to convert an array into a list of parameters to a > method. Since [] is a method, this happens to work well for including an > array into another array. But that's not its purpose, just a side effect. > > There's no real concept of converting a hash into a list of parameters to > a function, so there's no splat notation for it. Not so for Ruby 2.0, assuming we do indeed get key parameters: def foo( **keys ) p keys end > If you want to combine hashes, use the merge method > > {:c=>3}.merge(h) #=> {:a=>1, :b=>2, :c=>3} And with arrays one can use #+. That's fine, but it lacks a certain elegance in some instances. T.