From: Richard Kilmer Date: 2004-06-08T11:38:23+09:00 Subject: Re: How to ducktype a Hash? On 6/7/04 10:07 PM, "David A. Black" wrote: >> The key is expressing that a method you are defining is semantically >> equivalent to a method in another class/module. > > What happens if the method in the other class or module gets > redefined, with new semantics? > > > David What happens if you override the << method on Array to say, just ignore the parameter? Lots of bad stuff. If you change the semantics of a class at runtime, you should know the consequences...Ruby allows it, and that is fine, but "with great power comes great responsibility" ;-) But to really answer your question, if you say in Ruby 'my foo method is equivalent to that other classes foo method' then you change the meaning of the foo method on that class, from Ruby's perspective you are still equivalent. Its just a hint. Although, it would be cool to create an internal link from Hash's foo method with those that declare equivalence, that way if you do this: class Foo def [](key) #...do something 'hashlike' end end class Hash def [](key) return Time.now end end Ruby could raise a Warning... Warning line xxx: Class Foo's [] method has declared equivalence with Hash's [] method, changing this method could have unforeseen consequences. Or something like that... -rich