Hi,
In message "[ruby-talk:8218] Re: My first impression of Ruby. Lack of overloading? (long)"
on 00/12/29, Dave Thomas <Dave / PragmaticProgrammer.com> writes:
|> Ok, now what did I miss, and what is the rationale for no overloading,
|> or the replacement for it that I missed?
|
|I'll leave that one for Matz: there's a section in his book all about
|coerce: perhaps he might be able to cut and paste it here.
You mean the coercing section in chapter 7? But it's for numbers only.
I'd add method overloading according their dynamic type of arguments,
iff I can think of a specification which is affordable and consistent
with rest of Ruby. But I have little hope about this issue.
How about using "double dispatch"?
class Foo
def action(arg)
arg.action_Foo(self)
end
end
class Bar
def action_Foo(arg)
... action for combination of Foo and Bar
end
end
class Baz
def action_Foo(arg)
... action for combination of Foo and Baz
end
end
matz.