From: Aryk Grosz Date: 2008-04-21T08:28:21+09:00 Subject: Re: shortcut for x = unless x.is_a?(Array) Hey guys, I just read through this whole thread. I've really thought this through. What I was really trying to do all along was this. x = [x] unless x.is_a?(Array). I know this sounds redundant, buts that what I want and thats all I want. In the case of most types, the to_a and Array() can get you by, but when you don't know what type it is (especially when it could be a hash), I defined this function to flat out just do what I want it to do. class Array def self.wrap(value) value.is_a?(Array) ? value : [value] end end Simple, to the point, and no corner cases...is my solution. So: g = {:x=>1, :y=>2} Array.wrap(g)[0].is_a?(Hash) ==> true Done. -- Posted via http://www.ruby-forum.com/.