From: Sean O'Dell Date: 2004-06-06T02:30:47+09:00 Subject: Re: How to ducktype a Hash? On Saturday 05 June 2004 02:28, Robert Klemme wrote: > Maybe I got something wrong here, but I thought the idea of duck typing was > to just use the instance as a hash and get bitten if it's not. After all, > either way an exception will be thrown. If you don't throw an exception > you can still catch NoSuchMethodEx and treat it appropriately. The problem isn't that the object doesn't respond to the methods I need, it's that it DOES respond to the methods I need, but the methods don't do what I expect them to do. In this case, duck-typing simply doesn't work for me. I found this error through duck-typing, but it existed for weeks before I realized that some objects were quietly trashing sections of data I was passing around, because strings, arrays and others all respond to [] and []=, but DON'T contain objects quite the same way hashes do. 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. Sean O'Dell