From: Shadowfirebird Date: 2008-08-13T01:39:51+09:00 Subject: Re: How do I unsplat something? # this do? def unsplat(x) return [x].flatten end On Tue, Aug 12, 2008 at 5:21 PM, Patrick Li wrote: > Hi, > Is there any easy to unsplat an item? > ie. 1 becomes [1] > [2,3] remains [2,3] ? > > so far i found: > a = *[1] > *b = *a #=> [1] > a = *[1,2] > *b = *a #=> [1,2] > > but this doesn't work if a is a hash, because hash overrides the to_a > method > a = *[{"a"=>1}] > *b = *a #=> [["a",1]] when i actually want: [{"a"=>1}] > > Thanks for helping > -Patrick > -- > Posted via http://www.ruby-forum.com/. > > -- All you can do is try to know who your friends are as you head off to the war / Pick a star on the dark horizon and follow the light