From: Sean O'Dell Date: 2004-06-07T01:05:14+09:00 Subject: Re: How to ducktype a Hash? On Sunday 06 June 2004 00:53, George Ogata wrote: > "Sean O'Dell" writes: > > That's just a confidence issue. I don't care if the object coming in is > > broken. I'm not concerned about catching objects which are implemented > > improperly; that's actually very rare. If an object had a signature that > > said "I am a hash-like object" that would be fine for me. > > So if throughout the standard library, all "Hash-like" objects would > implement a #hashlike? method, that would be fine? It seems > unreasonable to me to expect that everything in the standard library > have a "X_like?" query method (or any other mechanism) for all > possible behaviours X. No matter what, you'll probably at some point > run into a situation where you want just one more method-or-something > that says that this object has some other behaviour. Whatever the "interface" description is, that's the rule. If an object said "I am hash-like," that would be a good start. Everyone wants more, but that's not the issue. I would just like if objects in Ruby could somehow describe what they do by simply declaring themselves as being of a certain type, or declaring that they implement certain interfaces. > > Duck typing and checking respond_to? are completely inadequate, and > > it seems like people argue those points because Ruby offers nothing > > else and so what are you going to advocate? It's those two or > > rolling your own interface identification system, which I think is > > cheesy; that sort of functionality should come from the framework. > > Sorry for being slow, but I have no idea what you're after. Could you > give an example of what you'd like to be able to write to achieve what > you want? object.implements(:hash_interface) Sean O'Dell