From: Richard Kilmer Date: 2004-06-07T23:18:14+09:00 Subject: Re: How to ducktype a Hash? I'm going to chime on this thread in two areas: 1) Having a fairly large 10K Ruby framework Running across over 300 machines I can safely say that Ruby scales fine...and I duck type when it makes sense and I use kind_of? when it makes sense. The code stresses all aspects of Ruby to a pretty large extreme (including threading, networking, parsing). We have about 20 folks now writing Ruby code so its a decent large contribution (ie. not just one programmer) although I manage the main body of code. We have had issues over the years in debugging, etc, but the enormous benefits we get from Ruby so far offset these issues that (although painful) they are worth it. 2) Sean: It seems like what you are looking for is to check a method for 'semantic equivalence'...that is, you want to say that the [] and []= methods on an object are semantically equivalent to the [] and []= methods on Hash. Not that the object is in any way (from and inheritance perspective) related to a Hash, nor does it actually get the behavior of a Hash object's [] and []= methods, but when it comes to those two methods...'quack like a Hash'. Does that sound right? If so, the question becomes how to express this kind of semantic equivalence both in the definition of the methods, and the checking with respond_to? -rich On 6/7/04 9:27 AM, "David A. Black" wrote: > Hi -- > > On Mon, 7 Jun 2004, Dave Burt wrote: > >> param.respond_to? '[]' and >> param.respond_to? '[]=' and >> !param.kind_of? String and >> !param.kind_of? Array > > That's not duck typing (see Dave's description(s), especially recent > clarification that duck typing isn't about checking things) -- also, > it would run aground on: > > class C > def [] > puts "Hello!" > end > end > > I think what we may be running into is the possibility that > "ducktyping a Hash" is in a sense a contradiction in terms. > > > David