On Saturday 05 June 2004 15:03, Ara.T.Howard wrote:
>
> in otherwords he is __exactly__ wanting to know if object posses certain
> methods with certain signatures (a #[] methods which takes any 'ol object
> for instance).  this is asking if an object implements an interface -
> albeit a small one.  in fact duck typing has always struck me as objects
> implemnting fine grained (and perhaps dynamic) interfaces.  my approach is
> simply this: ruby can't tell me this efficiently now, so, iff all objects
> can be known before runtime, i'll simply mark them.  i don't see this as
> checking ancestry because one could have easily done this via some other
> form of marking:
>
>    class HashLikeA
>      def is_hashlike?; true; end
>      ...
>    end
>
> in fact.  i can't imagine any efficient form of builtin duck typing which
> would not be some sort of aggregate method/signature checking - it's simply
> too costly to check each method and signature every time.  but perhaps i'm
> wrong...  hopefully in fact ;-)

This is the solution I am going with now.  In fact, if Ruby itself had this 
sort of "interface identification" built-in, it would suit me perfectly.  I 
don't believe that respond_to? really tells you much about an object's 
interface.  Two objects can respond to the same method name, but do 
COMPLETELY different things.  Duck typing doesn't work, and checking 
respond_to? doesn't work.  The only way to REALLY know if an object 
implements a certain interface is if you can positively identify it directly.  
Somehow, the object has to say "I implement the hash interface."  Whether 
that's just a simple flag, or if Ruby can somehow match it's methods to an 
interface description, or whatever, I don't care.  All I want to know is if 
an object implements a certain interface.  I don't care about ancestry, what 
methods it responds to, and I don't like just calling the object's methods 
and crossing my fingers.  Errors slip through quietly like that, and except 
for people who don't really care about that sort of thing, it doesn't work.  
It just doesn't.

	Sean O'Dell