From: torehalv@... (Tore Halvorsen) Date: 2004-09-17T22:44:46+09:00 Subject: Re: Automatic class conversion / function overloading Brian Candler wrote: [...] >Essentially it's what you've written. However, you'll find that in >more cases than you expect you don't actually do it. As long as the >objects passed in respond to the same methods, you can just invoke >them without caring what the class is; there is no need for them to >be inherited from some common superclass as would be the case in C++. [...] Thanks for helpfull info, but still... I agree, but when trying to make a class for rational numbers, I wanted to be able to multiply both rational and fixnums to it. class Rational attr_reader :u, :d #up, down def *(other) Rational.new(self.u * other.u, self.d * other.d) end end This obviously doesn't automatically work when passing a Fixnum as the argument. The C++ way is to create an automatic converter - or function overload. So the ruby way here would be: class Rational attr_reader :u, :d def *(o) case other when Rational other = o when Fixnum other = Rational.new(o, 1) end Rational.new(self.u * other.u, self.d * other.d) end end ? I need a ruby-idioms book :) -- Eld p� �ren og sol p� eng gjer mannen fegen og fj�g. [J�tul] /o)\ 2004 Tore Halvorsen || Cell: +052 0553034554 \(o/