From: Sean O'Dell Date: 2004-06-06T09:30:29+09:00 Subject: Re: How to ducktype a Hash? On Saturday 05 June 2004 15:01, John W. Long wrote: > >why do you need to say 'it is hash like' ? > >Wo'nt it be easyer to say 'I need this methods, so I'll just check > >them' ? > > > >BTW, probably the simpler solution is : > > > >x.methods =={}.methods > > This is even worse than object.kind_of(Hash). The whole point of "duck > typing" (as I understand it) is that you don't check if an object has > certain methods. You just use them. Ruby will throw an error if there's > a problem. Which always sounded fine to me until I was actually exposed to this kind of "typing." The problem is, the methods [] and []= are there, they just don't do what I need them to do. Duck typing completely and utterly don't help, and Ruby has no way to tell me when an object's [] and []= are hash-like or something else. My solution is going to end being something like "tagging all objects that I know in advance to be hash-like, and then looking for that tag at that particular point in my code." That's a kludge to me. Sean O'Dell