From: Robert Klemme Date: 2011-01-18T18:27:35+09:00 Subject: Re: Why Ruby Does Not Support Method Overloading? On Tue, Jan 18, 2011 at 2:09 AM, Su Zhang wrote: > Method overloading is ideally a feature only for statically typed > language, in which the binding of method names can be easily made at > compile time. Function/method names as well as the statically typed > formal parameters are all parts of the formal names used during early > binding. However, with a dynamically typed language (especially those > who have a method dispatch implementation similar to Smalltalk), only > the method name is considered part of the formal message content during > method dispatch (late binding). There is also a more fundamental reason to consider disallowing method overloading with different argument signatures: each method that shares the same name (identifier) should do the same. If however arguments have different types methods cannot do the same - strictly speaking. Of course, this is an extreme point of view but you have to ask yourself where you draw the line for "same". In languages with interfaces (e.g. Java) ideally all appropriate argument types implement the same interface and you need only one method anyway - or all argument types inherit from a common base class. In Ruby however which has duck typing you can pass in anything as long as "anything" responds to all methods needed - hence there is less demand for overloading. You can do class IntSum def initialize; @s = 0; end def add(x) @s += x.to_int # or x.to_i end end where you would need multiple methods for different argument types in other languages. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/