From: Robert Klemme Date: 2011-01-18T17:02:20+09:00 Subject: Re: Why Ruby Does Not Support Method Overloading? On Tue, Jan 18, 2011 at 2:09 AM, Su Zhang wrote: > From my understanding, taking the number of arguments, runtime type of > arguments or even the formal parameter names into account for message to > method mapping will complicate the language implementation. ... and method lookup tables will potentially be larger. Dunno whether this is a critical factor though. > This is also > the reason why Ruby does not support multiple dispatch at the language > level. Common-Lisp does support multiple dispatch, but it does so by > including a type modifier to the arguments so that they can be checked > against the actual runtime type of arguments, which, IMO, is as > unpleasant as doing something like the following in a single method > definition: > > case arg > when String >    # ... > when Symbol >    # ... > end For multiple arguments the unpleasant variant looks like this (1.9 and later): def f(*args) case args.map(&:class) when [Array, Array] puts "Array * 2" when [String, Array] puts "String, Array" when [Hash] puts "Hash" else raise ArgumentError, "Don't know what to do with %p" % [args] end end Cheers robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/