From: Ferenc Engard Date: 2003-09-13T05:38:47+09:00 Subject: Re: Mthod redefinition Hello, This is something you want: ------------------------------ class Foo def aMethod(param) # Based on param's type, call the appropriate function if param.kind_of?(String) return aMethod_string(param) end if param.kind_of?(Integer) return aMethod_integer(param) end end def aMethod_string(param) # ... end def aMethod_integer(param) # ... end private :aMethod_string, :aMethod_integer end ------------------------------ OTOH, the ducktyping is just you have said (if I correctly understand): if it can quak, it's a duck, if it can speak, it's a human. You can inspect what an object can do with the respond_to?() method: ------------------------------ class Foo def aMethod(param) # Based on param's capabilities, # call the appropriate function if param.respond_to?(:quak) return aMethod_quaks(param) end if param.respond_to?(:speak) return aMethod_speaks(param) end end # It can quak, who cares what this param really is? def aMethod_quaks(param) # ... end def aMethod_speaks(param) # ... end private :aMethod_quaks, :aMethod_speaks end ------------------------------ Both are untested code, sorry if something do not work. Regards: Circum