From: "Einar Magnús Boson" Date: 2008-11-17T16:57:53+09:00 Subject: Re: How can I overload a method in Ruby I find that overriding is much more powerful. You can override just about any method. Try class Fixnum def to_s "this is kinda stupid" end end puts 5 Overloading is mostly used for default arguments anyways isn't it? and also requires static typing I think. Einar Magnús Boson +354-661 1649 einarmagnus@tistron.se einar.boson@gmail.com On 17.11.2008, at 07:50 , Zhao Yi wrote: > Einar Magnús Boson wrote: >> 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" > > ok I understand. Just curious, overload is a good feature in OO > programming. Why doesn't Ruby support it? If I use the method you > mentioned, I have to check the parameters and use if - else or swith > to > distinguish them. > -- > Posted via http://www.ruby-forum.com/. >