From: Brian Adkins Date: 2008-11-28T10:35:09+09:00 Subject: Re: Ruby's duck typing Robert Dober writes: >> Ruby doesn't support generic functions, so there's a limit to this >> approach, > Which limit Brian? I do not see anything Ruby cannot do where you > *have* to use generics in other languages. > Do I miss the obvious here? No, you didn't "miss the obvious" because I didn't provide much detail :) If you consider two models of OOP, message passing and generic functions, Ruby/Smalltalk would be an example of the former, Common Lisp would be an example of the latter. With message passing, you can specialize the first parameter (e.g. self). With generic functions, you can specialize on multiple parameters. As Paul Graham stated, "In the message-passing model, methods are *of* objects, while in the generic function model, they are specialized *for* objects. The approach I mentioned has limitations with respect to inheritance i.e. if "get_field" need to be specialized for various types. It was more in the "style" of generic functions (not *belonging* to an object), but without language support, so it's going against the grain a bit. In many cases it's a reasonable mechanism (i.e. a more functional approach), and can allow for simpler reasoning about the function since it doesn't have dependencies to the class. > Generics are used to create instantiations of a generic for given type > parameters. As there are no types in ruby > the method just takes the place of the generic function. "generic function" not "generic type" > Robert > > -- > Ne baisse jamais la t�te, tu ne verrais plus les �toiles. > > Robert Dober ;) > -- Brian Adkins http://www.lojic.com/ http://lojic.com/blog/