From: "Jesús Gabriel y Galán" Date: 2008-11-28T20:41:17+09:00 Subject: Re: Ruby's duck typing On Fri, Nov 28, 2008 at 12:25 PM, stephan.zimmer wrote: >> As Paul Graham stated, "In the message-passing model, methods are *of* >> objects, while in the generic function model, they are specialized >> *for* objects. > > It might be naive, but wouldn't it be possible to simulate a generic > function by simply accessing the types of the parameters (using > "is_a?") and then provide different function bodies for different > parameters? For this you can take a look at facets/overload, which allows things like: class X def x "hello" end overload :x, Integer do |i| i end overload :x, String, String do |s1, s2| [s1, s2] end end (taken from facet's doc: http://facets.rubyforge.org/doc/index.html) Jesus.