From: Sean O'Dell Date: 2004-06-06T14:06:24+09:00 Subject: Re: How to ducktype a Hash? On Saturday 05 June 2004 20:23, Dave Thomas wrote: > On Jun 5, 2004, at 19:24, Sean O'Dell wrote: > > No, it IS my problem. My code quietly does some really undesired > > things when > > non-hash-like objects get to this one point in code. I hate this > > attitude > > about typing. I know you mean well, and it's been talked out to > > death, but I > > don't buy the whole thing about "if it has the methods, it must be > > fine." > > It's clearly NOT fine. If an array or a string, both which have the [] > > methods I need, get to this one place, I drop a whole branch of data > > being > > passed around. > > Then you need to test to make sure your parameter is a Hash. Duck > typing isn't applicable, as your code is coupled to the behavior of a > particular class. The objects are not always a Hash per se, just objects with hash-like functionality. But, as I said, other objects can slip in too, like strings and arrays, which have [] and []= methods, but which don't act like hashes at all. Sean O'Dell