From: Trans Date: 2008-11-17T22:40:54+09:00 Subject: Re: How can I overload a method in Ruby On Nov 17, 2:26 am, Zhao Yi wrote: > This is my class definition: > class Impl >   include MyModule >   def fun() >     puts ("fun") >   end > >   def fun(directory) >     puts ("fun directory") >   end > end > m=Impl.new() > m.fun() > > When I run this program, I got this error: > > class_objects/module.rb:22:in `fun': wrong number of arguments (0 for 1) > (ArgumentError) >   from class_objects/module.rb:22 > > I declared two methods with the same name but different parameters. Why > can't ruby support overload method? Although it is not the "Ruby Way" so to speak, Ruby is flexible enough to allow for ways to do it. For instance: require 'facets/overload' class X def x "hello" end overload :x, Integer do |i| i end overload :x, String, String do |s1, s2| [s1, s2] end end