From: Jean-Hugues ROBERT Date: 2004-06-10T17:28:00+09:00 Subject: Re: [ANN] Ruby/Interface At 04:55 10/06/2004 +0900, you wrote: >I decided the library wasn't "Ruby" enough and I got some ideas from Daniel >Berger's interface library, so I made a lot of changes. > >Homepage: http://interface.rubyforge.org/ >Rubyforge Project Homepage: http://rubyforge.org/projects/interface/ >Download: http://rubyforge.org/frs/?group_id=266&release_id=529 > >Code Snippet: > > require "celsoft.com/interface" > > HashInterface = Interface.new > > HashInterface.add_class_patterns(Hash, :[], :[]=) > HashInterface.add_pattern(:each_pair, proc{||}) > > class Hash > implements HashInterface > end > > class< implements HashInterface > end > > p Hash.new.implements?(HashInterface) == true > p ENV.implements?(HashInterface) == true Should be implement?() vs implements?() I believe. See include?() for example. That is a nice Ruby idiom. Also: You are using both "declarative" (like "implements") and "imperative" styles (like "add_pattern). I feel like "declarative" style would be appropriate in both cases. OTOH that might be a matter of style/taste. Yours, JeanHuguesRobert EOM > HashInterface.add_pattern(:each_pair, proc{|a|}) # method param changed > > p ENV.implements?(HashInterface) == false > >How It Works > >Method patterns are stored with each Interface object and are used to check >against the methods of any given object. The name and number of parameters >are important. If an object never claims to implement an interface, it will >always report that it does not implement a given interface, even if it may be >capable of it. When an object claims to implement an interface, a thorough >check is performed to verify that it actually does. This check is only >performed when necessary for efficiency, when implements? is called. The >result of the check is cached and returned quickly on subsequent calls to >implements?. If either the interface definition changes, or methods are >changed in the class of the object, the cache is dumped and the thorough >check is performed the next time implements? is called, and the answer is >then again cached. ------------------------------------------------------------------------- Web: http://hdl.handle.net/1030.37/1.1 Phone: +33 (0) 4 92 27 74 17