From: "David A. Black" Date: 2007-10-23T01:39:56+09:00 Subject: Re: Conflicts between using respond_to? and extending Ruby Hi -- On Tue, 23 Oct 2007, Rick DeNatale wrote: > On 10/22/07, David A. Black wrote: > >> What I've always called the soft/hard duck typing distinction isn't >> quite the same as what you're calling the chicken/duck distinction, >> though, in the sense that I rule is_a? and kind_of? completely out of >> bounds as duck typing of any kind. Duck typing, as I understand it >> from various writings by, and exchanges with, Dave Thomas, starts >> where is_a? leaves off. respond_to? starts to enter the duck-typing >> orbit, in the sense that at least it's focused on the object and its >> capabilities, rather than its class/module ancestry (and that's the >> most decisive line to cross). Since it still falls short of simply >> asking the object to do something, I consider it a "soft" form of duck >> typing. It's object-driven, but not atomic. > > One difference between kind_of? and respond_to? is that it's slightly > more likely that a particular method or methods mean what the chicken > typer expects when using kind_of? than respond_to?, since kind_of? is > testing an implementation relationship, but that's by no means > guaranteed. > > The notion of 'type' held by the user of an object is often more > complex and or general than just being in a particular implementation > hierarchy, or responding to a certain set of verbs at the lexical > level. So I don't see so much of a distinction between respond_to? > and kind_of? The distinction I see is proximity to the object. respond_to? is asking the object about its capabilities, whereas kind_of? is asking it about its ancestry. So respond_to? is a tighter fit with the object as it is at a given point in runtime. David -- Upcoming training by David A. Black/Ruby Power and Light, LLC: * Advancing with Rails, Edison, NJ, November 6-9 * Advancing with Rails, Berlin, Germany, November 19-22 * Intro to Rails, London, UK, December 3-6 (by Skills Matter) See http://www.rubypal.com for details!