From: James Britt Date: 2004-06-07T01:53:41+09:00 Subject: Re: How to ducktype a Hash? David A. Black wrote: wanted to spotlight some underlying concepts; but let me weave it in, > or layer it on. > > The term "duck typing", as I understand it, is not itself a reference > to Ruby's distinction between class and type but is, rather, an > approach to Ruby programming that is built on top of a recognition of > that distinction. Exactly where one draws the line may vary. (I've > always liked to say, "Programmers don't do duck typing; Ruby does", > but I think Dave Thomas actually had in mind something that > programmers do with Ruby, and I'll go along with that :-). The > important thing is that duck typing is not something imposed on Ruby > from the outside; it's a follow-through on observations about the > basic state of things as governed by Ruby's design. (See > http://www.ruby-talk.org/78502 for Dave Thomas on duck typing.) > > This is important because sometimes people talk about duck typing as > if, by *not* doing it, you were deciding that Ruby wasn't being as > dynamic as it would be if you were doing it. But Ruby's type system > is there all the time. Even calls to #kind_of? are, in the end, Ruby > method calls, with all that that implies. This is an important point. Earlier in this thread there was a comment along the lines of, "If Ruby was built for duck typing, why weren't the standard libs better designed to manage the quirky cases?" It struck me as an odd, and misguided, question, because duck typing is more of an epiphenomenon. It's not a target of the language design, it's just one of the things you get as a result. And, as with so much in Ruby, you can use or not, and change things around when and where needed. James