From: Brian Adkins Date: 2008-11-29T03:29:59+09:00 Subject: Re: Ruby's duck typing "stephan.zimmer" writes: > Robert, Sean, Brian, > > many thanks for your answers and the very interesting discussion. > >> Look at this approach >> http://pastie.org/325446 >> hopefully you find it helpful. > > Ya, that's really nice, also to me delegation seems more reasonable > than inheritance in many cases. I will utilize it. The "factory > approach" is also nice, I never thought about it. I think it gives > handy code. > >> 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? Don't get me wrong - I love Ruby, but Ruby is slow enough already w/o introducing an interpreted multiple dispatch mechanism. It certainly could be done, but I wouldn't recommend it. Double dispatch might be worth considering, but that would get ugly with more params. Simple functions that depend on duck typing wrt parameters works fine, but if inheritance is needed, then using Ruby's inheritance model would be superior to simulating generic functions. > Is there any document, paper, etc. which states more details about the > Ruby type system, as design motives, comparisons to other languages, > etc.? > > Best, > > Stephan -- Brian Adkins http://www.lojic.com/ http://lojic.com/blog/