From: Sean O'Dell Date: 2004-06-08T01:39:55+09:00 Subject: Re: How to ducktype a Hash? On Monday 07 June 2004 07:33, Vlad wrote: > "Sean O'Dell" wrote in message > news:<200406041915.32644.sean@celsoft.com>... > > > 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. > > > > Sean O'Dell > > Guess, you will be happy if Ruby can do some like ... > > obj.respond_to?(Hash::[]) > or > obj.respond_to?(Foo::[]) Yes, if obj.respond_to?(Hash::[]) can be called for non-Hash objects, and for objects that don't derive from Hash, but which implement hash-like functionality. The semantics aren't important. That method of interface checking would work as well as any. Sean O'Dell