On 2003.01.13, Tim Bates <tim / bates.id.au> wrote: > On Mon, 13 Jan 2003 05:07 pm, Tom Sawyer wrote: > > i wonder, a coding challenge of sorts, what would it talk to create an > > Array_Of(AClass) constructor? such that an array would be created that can > > only contain objects of the class specified. > > Oh, so you want type checking now? ;) > > Pretty simple, I would think. Find all the methods that can add or change > elements in the array, and add type checks to it. I think, staying in line with OO principles, #all_responds_to?(x) would be more appropriate. Then, you could say: a = Array.new a << "hi" a << "there" if a.all_responds_to? :upcase puts "Everything in array 'a' knows how to upcase itself." end Or, of course, something slightly more useful. -- Dossy -- Dossy Shiobara mail: dossy / panoptic.com Panoptic Computer Network web: http://www.panoptic.com/ "He realized the fastest way to change is to laugh at your own folly -- then you can let go and quickly move on." (p. 70)