From: Jeff Mitchell Date: 2004-06-06T05:12:53+09:00 Subject: Re: How to ducktype a Hash? --- Sean O'Dell wrote: > On Saturday 05 June 2004 10:39, Dave Thomas wrote: > > On Jun 5, 2004, at 12:30, Sean O'Dell wrote: > > > I just don't like this duck-typing business. I can handle dynamic > > > typing, but > > > I wish there were something more solid about the typing, at least a > > > way to > > > know when an object implements a certain interface or not, so I can > > > tell an > > > array-like object from a hash-like object. > > > > Perhaps you could design the interface to your classes so that the > > distinction is either explicit or irrelevant. > > It's not my classes that are the problem, it's all of the other objects that > respond to [] and []=, but which aren't hash-like (they're array-like, and > even then it's anyone's guess as to the functionality). Could you use explicit names such as #lookup and #store ? I realize it's not as convenient as [], but the problem is that [] is overloaded with meaning. Perhaps that's what Dave is suggesting. Thus you'd add #lookup and #store to Hash and all things Hash-like. With these explicit names you can duck-type without running into geese and other imposters. __________________________________ Do you Yahoo!? Friends. Fun. Try the all-new Yahoo! Messenger. http://messenger.yahoo.com/