From: Thomas Date: 2005-05-23T17:44:13+09:00 Subject: Re: Uniform vector class, inheriting from Array: How to make sure that methods return a Vector and not an Array? > I'm quite shure you don't need to do what you are doing, because this > violates duck typing Thank you very much for pointing out how to use method_missing here. BTW I don't think that it "violates" duck typing. The idea is to have a collection type class with "entrance rules" that can guarantee that every single element complies with some sort of standard/interface/rule set/constraints/contracts ... Using kind_of? is only one possible constraint here. Another one could be respond_to?(:quack). On the long run, I would like it to look/feel like this: class QuackQuack < UniformArray add_contstraint lambda {|e| e.respond_to?(:quack)} end class ArmyOfDucks < UniformArray add_contstraint lambda {|e| e.kind_of?(Duck)} end class FlockOfDucks < UniformArray add_contstraint lambda {|e| e.kind_of?(Duck)} permit nil # There may be nil values allow :nested # The array may be nested end d = UniformArray.new d.add_contstraint lambda {|e| e.kind_of?(Numeric) and e >= 0 and e <= 10} d.add_handler lambda {|e| e > 10 ? 10 : 0} etc. I don't think this is incompatible with duck typing. It's just some sort of specialized collection type of class. Cheers, Thomas.