On 5/11/07, dblack / wobblini.net <dblack / wobblini.net> wrote:
> Hi --
>
> On Sat, 12 May 2007, Rick DeNatale wrote:

> >
> > Not exactly the same thing though, if you don't know that the obj
> > isn't already an array then there's no guarantee that
> >
> > [obj] == obj.to_a
> >
> > obj = 1
> > [obj] #=> [1]
> >
> > obj = %{already an array}
> > [obj] #=> [['already', 'an', 'array']]

>
> I think that the * operator will (always?) do it:
>
>    [*1]   # => [1]
>    [obj]  # => ["already", "an", "array"]

Yep, as long as you actually USE it <G>
irb(main):001:0> obj = %w{already an array}
=> ["already", "an", "array"]
irb(main):002:0> [*obj]
=> ["already", "an", "array"]

I'm not sure whether or not the to_splat changes in Ruby 1.9 will have
a subtle effect on this though.

-- 
Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/