From: "David A. Black" Date: 2005-01-26T21:25:15+09:00 Subject: Re: Injecting methods from one class into another. Hi -- On Wed, 26 Jan 2005, George Moschovitis wrote: >> You're forgetting something. It's not "If it quacks...", it's >> "If it quacks... and if it walks...". > > not really! > > The method I want to inject ONLY cares for quacking, NOT walking, so > for this method, an object that quacks IS a Duck. > > The same happens with Ruby's to_s: > > Array (~Hawk) implements to_s, so for puts it is a String (~Duck) > George. But remember, it's duck with a small 'd' :-) It doesn't mean "the object can be treated like an instance of some specific existing Ruby class". Rather, it's a way of describing type without reference to class/module ancestry. One might paraphrase it, perhaps, as: If it walks and quacks, then it walks and quacks. with the implication that (a) that's all you need to know, and (b) these capabilities unite this object with other objects with the same capabilities. David -- David A. Black dblack@wobblini.net