Todd Benson
3/11/2008 2:04:00 AM
On Mon, Mar 10, 2008 at 6:16 PM, Paul Mckibbin <pmckibbin@gmail.com> wrote:
>
> > => some warning about default to_a being deprecated
> >
> > Todd
>
> which is why x=Array(x) would be better.
>
> Mac
Like your original response, it depends on what you want to do.
x = {}
Array[x] == Array(x)
=> false
In this case -- with the result -- one encapsulates, the other
modifies. Same thing with NilClass and Range. I added a line to your
code to see this for sure...
TEST=[[1,2,3],(1..3),{:a=>:b},1,"test",true,nil,/123/]
TEST.each do |x|
puts x.class
puts '============================'
puts "#{x.inspect}.to_a gives #{x.to_a.inspect}"
puts "[#{x.inspect}] gives #{([x]).inspect}"
puts "Array(#{x.inspect}) gives #{Array(x).inspect}"
puts "Array[#{x.inspect}] gives #{Array[x].inspect}"
#added this ^^^^^^ one
puts '============================'
end
Todd