From: "David A. Black" Date: 2005-08-04T05:07:52+09:00 Subject: Re: [RCR] array or with non-array On Thu, 4 Aug 2005, Eric Mahurin wrote: > --- "David A. Black" wrote: > >> class != type. Type is at the heart of duck-typing; class >> isn't :-) > > > Huh? Where do you get that? Duck-typing is about not caring > about what the type/class the object is. Duck-typing in the Class is irrelevant, but you'd be well-advised to care about what the type is, or you'll find yourself with a lot of NoMethodErrors :-) > purest sense is calling the methods of the arguments without > regard to what the class of the object is. An object's type is the sum of all of its capabilities. Duck typing involves focusing on an object's capabilities -- its type -- and not worrying about its class. You also don't have to "worry" about its type (and I agree with those who say that duck typing does not mean sticking respond_to? everywhere). But you are dealing with type -- dealing with it, in the sense of making assumptions about it, writing code governed by those assumptions, etc. -- and not dealing with class. I like Jim Weirich's characterization of Ruby as "a duck-typed language", because it captures the fact that, in a sense, one is always doing duck typing in Ruby. That's also why I always feel uneasy with meta-concepts like the "duck type" of an object. What people sometimes call the "duck type" of an object, I call simply the type of the object. Duck typing, in that respect, is a way of describing an approach to programming that arises very organically from Ruby. David -- David A. Black dblack@wobblini.net