From: Todd Benson Date: 2008-03-11T11:03:56+09:00 Subject: Re: shortcut for x = unless x.is_a?(Array) On Mon, Mar 10, 2008 at 6:16 PM, Paul Mckibbin 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