From: Doug Glidden <41mortimer@...> Date: 2008-08-29T10:31:46+09:00 Subject: Re: Class === Patrick Doyle wrote: >> Forgive me if I'm missing something obvious, but wouldn't it be a whole >> lot more logical to do this? >> >> if x.is_a? Array >> ... >> end > yup... that makes good sense too. > > This is a great night! :-) > > --wpd Even better, if its possible you'd want to use the method on a structure other than an array in the future, use 'respond-to?' instead. So for instance, if you're protecting a call to 'each': if x.respond_to? :each x.each do ... end end That way, it'll work not only with Arrays, but also with Lists and Hashes or any other Enumerable class (or any class that implements each). So if you later on decide that it would make more sense to store your data in a List instead of an Array, if you use 'is_a?' you'll have to go through and change your code every time you do this check, but if you use 'respond_to?', you won't have to change a single line! Of course, there are situations where 'is_a?' is necessary, but 'respond_to?' is generally preferable, from what I've seen. -- Posted via http://www.ruby-forum.com/.