From: Dimitrios Galanakis [mailto:galanaki@uiuc.edu]
I need to define a method that performs differently when
operated on objects of different type (overloading).
Currently I use various if’s to check for the type of
the object as follows:def somefunction(a)
if a.kind_of?(someType)
expression1
return
end
if a.kind_of(someOtherType)
expression2
return
end
end
I would do it like this …
class SomeType
def somefunction
expression1
end
end
class SomeOtherType
def somefunction
expression2
end
end
Then just call:
a.somefunction
If you still feel the need to pass obj as an argument to somefunction, you
can always use:
def somefunction(a)
a.somefunction
end
···
–
– Jim Weirich / Compuware
– FWP Capture Services
– Phone: 859-386-8855