Phlip
4/20/2009 4:23:00 PM
Michael Satterwhite wrote:
> As much as I like Ruby, I do miss the polymorphic behavior of routines
> in Java and C++. There are frequently times in which it would be useful
> to have constructors (or routines) that take different arguments. I do
> see some constructors that may take arguments of different types, so I
> know people are doing it, but I'm curious as to how.
That's "overloading", not "polymorphism".
You do that in Ruby like this:
def zone(*args)
args.each do |arg|
case arg
when String
string_zone(arg)
when Fixnum
fixnum_zone(arg)
when MechaBattle
mecha_battle_zone(arg)
end
end
end
From here, learn what real polymorphism is! You prob'ly already use it...
--
Phlip