From: ptkwt@...1.aracnet.com (Phil Tomson) Date: 2002-09-13T05:40:53+09:00 Subject: Re: not grasping the method overloading/multi-dispatch thing In article <20020912151951.T25425@atdesk.com>, Paul Brannan wrote: >On Fri, Sep 13, 2002 at 03:40:42AM +0900, Phil Tomson wrote: >> Currently if we need a method that does two different things based on >> the type of an argument we have to do: >> >> def meth(s) >> case s >> when Integer >> #do something >> when Float >> #do something else >> end >> end > >This isn't necessary; see Hal's example of another alternative (declare >a method in the Integer and Float classes that gets called from meth(), >so that meth() follows the same code path for whatever type you use). Good point. >The downside is that you have to modify those classes in order for this >to work. > In Ruby it's not really considered a downside... it seems to be an acceptable practice. Perhaps this idea should be proposed as an idiomatic way of solving the problem - ie. "We don't need multi-methods since all classes are open in Ruby". Phil