--- Austin Ziegler <halostatue / gmail.com> wrote: > > Basically, when I call obj.quacks_like? Klass I ask if > every public > > method defined in Klass is defined in obj as well. > > I don't think it's what you want. I won't call it stupid, but > note that > StringIO can be used as an IO for most things -- but not all > things. In > general, the duck typing philosophy seems to be "does it > quack this way > at this time" -- being concerned only about a single method > at a time. To elaborate a little more, I think the normal time to think about duck typing is when looking at the arguments of a method. If that method only needs certain methods from that argument, any object that can does these (in the way used) could be used as a "duck". In practice you'll find there is almost never a need to make sure an object has an entire interface of methods. And even when you want the object to respond to certain methods, the duck-typing philosophy is to not worry about it with any code - just let the check occur automatically when you try invoking methods on the object/duck. I usually write my methods with duck-typing in mind. For each argument, I try to apply a minimal number of methods to it. And pick method names that allow a variety of objects (i.e. #[]). For example, if you expect something like a string for an argument and only use #[], you'll find that that argument can also be an Array, Hash, ... and the best: a Proc. That's the power of duck-typing. __________________________________ Yahoo! Mail - PC Magazine Editors' Choice 2005 http://mail.yahoo.com