From: Ryan Leavengood Date: 2001-11-03T01:54:29+09:00 Subject: [ruby-talk:24178] RE: Limits of dynamism? > class T > def initialize(o); @o = o; end > Object.new.methods.each {|m| undef_method(m.intern) unless m =~ /__/} > def method_missing(*a); @o.send(*a); end > end > t = T.new(a = Array.new) > > p t.class > p t.type > p t.kind_of?(Array) > p (t.id == a.id) > p (Array === t) # In the name of dynamism, shouldn't this give true? Well you have had to explicitly undef all of T's methods and implement method_missing to make it behave like the class it is delegating to. Why should you not have to modify Module#=== to make it work right with this delegation? class Module alias_method :__old_case_eq__, :=== def ===(other) if other.kind_of? self return true else __old_case_eq__(other) end end end Do this and it works. Otherwise Ruby uses its C API to determine the class of an object, which will return T for T. But by explicitly calling kind_of? we can delegate to the internal class and it works correctly. Ryan Leavengood