From: Kristof Bastiaensen Date: 2004-06-06T21:38:49+09:00 Subject: Re: How to ducktype a Hash? On Sun, 06 Jun 2004 14:47:31 +0900, Sean O'Dell wrote: > One test I can to really solve this problem is to create artificial tags > for Hashes, my objects and any other objects that get created either by > me or someone else as Hashes. That solution will work, but my complaint > is that it feels like such a kludge. My problem is solved though -- I > have several choices now. I just wish Ruby did this already. I am > getting bit by little stupid things that are hard to catch, and my > growing project is now starting to feel REALLY unstable. I never get > that feeling with C++, so I guess I should stop trying to use Ruby for > these larger projects. This one though, it started so nicely and > fast...but now, it feels sort of kludgy and I don't have a feeling of > confidence about its ability to either perform properly, or at least > report errors that I consider errors. Since there is no typing > mechanism at all, I can't tell Ruby "hey, anything but a hash-like > object here is an error." > > Hm, just an idea, but perhaps is tagging not such an ugly solution? You could create a dummy module Hashlike, include it in your hashlike classes, and test with obj.is_a? Hashlike or obj.is_a? Hash I guess it would work like interfaces in Java. Kristof Bastiaensen