From: Sean O'Dell Date: 2004-06-06T02:19:11+09:00 Subject: Re: How to ducktype a Hash? On Friday 04 June 2004 20:48, Claus Spitzer wrote: > On Sat, 5 Jun 2004 11:15:37 +0900, Sean O'Dell wrote: > > > In both cases, does that mean that the object has hash-like > > functionality, or just that the object responds to those two methods? Is > > there some definition somewhere that says "it's a hash if it has these > > methods?" I actually have hash-like objects that DON'T respond to either > > of those two methods, but it would be easy enough to add fake ones. I > > hate adding fake methods just to id a hash interface, it's a kludge. > > > Well, what exactly do all your hash-like objects have in common that > is not present in any other object? :keys is a pretty good identifier > for a hash... since I know of no other data structure that has a key > (mind you, I said "_I_ know of", there could well be one that I don't > know). . The problem is, there's no definition of what a hash-like object really is. If there were something I could depend on, I'd check respond_to? for that. For my own personal uses, all I care about is [] and []=. Sean O'Dell