From: Sean O'Halpin Date: 2007-10-23T05:29:29+09:00 Subject: Re: Conflicts between using respond_to? and extending Ruby ------=_Part_11391_31404378.1193084969494 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline On 10/22/07, ara.t.howard wrote: > > > respond_to? + arity it sometimes better. other alternatices are to > mark objects with modules > > module Marker; end > > object.extend Marker > > if Marker === object > > so you have a more controlled environment - facets could easily use > this approach. > On 10/22/07, ara.t.howard wrote: > > > respond_to? + arity it sometimes better. other alternatices are to > mark objects with modules > > module Marker; end > > object.extend Marker > > if Marker === object > > so you have a more controlled environment - facets could easily use > this approach. > I've been using something similar to this approach by using modules to represent sets of behaviours which a class should have. So you end up with class definitions like this (bogus example): class Duck include CanFly include CanQuack include CanSwim end i.e. composing the class definition from the set of behaviours or protocols it satisfies. Checking whether an object will fulfil your expectations then becomes: if donald === CanQuack This is a much stronger guarantee of behaviour than :respond_to? and still qualifies as duck-typing in my opinion (i.e. not based on inheritance). Regards, Sean ------=_Part_11391_31404378.1193084969494--