From: James Edward Gray II Date: 2007-03-02T11:45:47+09:00 Subject: Re: Duck Typing Hash-Like Objects On Mar 1, 2007, at 8:26 PM, dblack@wobblini.net wrote: > Hi -- > > On Fri, 2 Mar 2007, Gary Wright wrote: > >> On Mar 1, 2007, at 7:38 PM, James Edward Gray II wrote: >>> You're still type checking, you're just doing it in a more >>> fragile way. If you want to type check, use the class, I say. >> >> Yet if I test for (Hash == mystery_obj) that would not >> allow someone to pass an RBTree object instead, which I think >> is a very reasonable thing to allow and works just fine if >> I only use #fetch. > > I had the impression James was talking about the Integer and String > methods, though then again those aren't actually the classes. So I'm > not sure what he meant :-) I was probably just babbling, not making sense. I do that. > But I don't think it was just to test class membership, since that > manifestly doesn't help in the kind of situation you're describing. Yeah, you're right. I was feeling that this is just an attempt to sidestep type checking by inventing a clever new type checking system. It's really just trying to provide a flexible interface though. Given that, I'm changing my answer. This is a documentation problem. As long as the documentation tells me your method needs a put_stuff_in() and a pull_stuff_out() to work, tells me what they will be passed, and *doesn't* type check, you support ALL data structures. I can always wrap Hash, RBTree, Integer, JamesCustomDataVoid, or whatever in a trivial class implementing those calls. Am I making sense yet, or do I just need to go to sleep now? James Edward Gray II