From: "Einar Magnús Boson" Date: 2008-11-17T16:46:25+09:00 Subject: Re: How can I overload a method in Ruby --Apple-Mail-1--507116534 Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit there is no overloading, only overriding. You can have variable number of arguments by writing def fun(*params) #here params is an array of your arguments, [] if none. end you can also have a default value for your parameter: class Impl include MyModule def fun(directory = "") puts "fun #{directory}" end end m=Impl.new() m.fun() # >> fun m.fun "/dev/null" # >> fun /dev/null" On 17.11.2008, at 07:26 , 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? > -- > Posted via http://www.ruby-forum.com/. > --Apple-Mail-1--507116534--