From: Gavin Sinclair Date: 2004-06-08T20:32:56+09:00 Subject: Re: How to ducktype a Hash? Jim Weirich wrote: > Actually, I was going to write up a proposal but saw a posting > in ruby-talk:102752 that echoed my idea. We need a mixin module for > hashable (similar to Enumerable) that implements the basic functionality > of hashes on the basis of a small number of primitives. Then anyone > needing hash-like behavior would mixin this module and would get a fully > implemented Hash interface. > > Advantages: > * Full set of hash methods for the cost of implementing a small > number of primitives. > * Well defined semantics[1] for all the hash methods > * Easy to check test to see if something implements hash-like > behavior (obj.is_a?(Hashable)). I like the idea. Can you propose some details? And can it be called Map rather than Hashable? I presume you're talking about map semantics, involving mapping a key to a value, rather than hash semantics, involving calculating hash codes. obj.is_a?(Map) reads nicely to me. > I see a need for something like this for IO as well (eg. Readable, > Writeable). That seems less important than the much-discussed-from-all-angles Hash, but interesting nonetheless. Again, I'm hungry for details. Cheers, Gavin