David Vallner
10/19/2006 8:07:00 PM
Parv G. wrote:
> hello all,
> i'm new to ruby and need some help on what seems like a simple issue.
>
> How do i find out if the argument passed to a method is a string or an
> integer?
>
> Here's what i'm trying to do:
>
> def method_test(some_arg)
> if some_arg is string
> #callmethod A
> else
> #callmethod B
> end
> end
>
Not repeating the obvious
duck-type-but-not-really-cause-that-says-nothing-anyway, applying the
"replace conditional with polymorphism" refactoring is probably the
cleanest solution from an OO point of view. More so because this is
trivial with Ruby's open classes, and the standard library probably has
what you need (like a type conversion method).
David Vallner