From: Robert Klemme Date: 2004-09-19T20:44:42+09:00 Subject: Re: Automatic class conversion / function overloading "Brian Candler" schrieb im Newsbeitrag news:20040918162110.GA1146@uk.tiscali.com... > On Sat, Sep 18, 2004 at 12:17:57AM +0900, Markus wrote: >> > Btw: you know that there are classes Rational, Complex etc. already, do >> > you? >> >> Yes. But it's a convenient context for discussing the real issues >> (why overloading isn't as needed in ruby, how duck typing reduces the >> need for class-tests, etc.) since it's reasonable to assume that >> everyone knows what the semantics _should_be_ and thus we can focus on >> how they are best implemented. Ah, I see. > If you want to see an example of Ruby idiom in practice, just see > /usr/local/lib/ruby/1.8/rational.rb (or wherever it is on your system) > > The stuff with #coerce I never 100% understood, but then I've never had to > use it for any of my own classes. I've only ever seen it used for the > various different ways of representing numbers. I saw a really nice explanation of all these Ruby protocols (#coerce, #to_str etc.) - I don't exactly remember where it was, could be in Pickaxe II. Kind regards robert