From: Patrick Doyle Date: 2008-08-29T20:42:38+09:00 Subject: Re: Class === > 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 except... #each doesn't always mean the same thing to everybody. For Hashes, it means "each key and value pair" for arrays, it means "each value, but without the index". On my TODO list is to figure out what (virtual) paperwork is required to propose the addition of an #each_element method that _would_ mean the same thing to everybody. (For Arrays, it would be aliased to #each, for Hashes, it would be aliased to #each_value, for a hypothetical List class, it would be aliased to some iterator that yields the next element in the list. --wpd