From: George Ogata Date: 2004-06-06T16:53:40+09:00 Subject: Re: How to ducktype a Hash? "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. Some "tagging" mechanism (e.g., mixing in a module) seems logical and necessary. Yes, you'd have to retrofit your scheme onto all the existing classes that you decide implements this interface, but how can you expect not to -- you want to declare that classes implement an interface that didn't exist when the classes were first written. > 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?