From: dblack@... Date: 2006-07-25T05:36:21+09:00 Subject: Re: I'll have the duck! Hi -- On Tue, 25 Jul 2006, Daniel DeLorme wrote: > benjohn@fysh.org wrote: >> I also like it because I don't think that there's anything especially >> fundamental about classes. With predicate classes, all you're really >> saying is that "if I've got something that can do x and y, then I know >> that I can equally validly think of it as something that can do z". > > The concept really piqued my interest, and since ruby gives us such nice > metaprogramming abilities, why not do it? > > > module DuckTyping > @@quacks = Hash.new{ |h,k| h[k] = {} } [...] > Duck.new.quack_loudly #=> "QUACK!" > Dog.new.quack_loudly #=> NoMethodError I guess you'd have to think of a new name to refer to what has in the past been called "duck typing" :-) David -- http://www.rubypowerandlight.com => Ruby/Rails training & consultancy http://www.manning.com/black => RUBY FOR RAILS (reviewed on Slashdot, 7/12/2006!) http://dablog.rubypal.com => D[avid ]A[. ]B[lack's][ Web]log dblack@wobblini.net => me