From: Ron Jeffries Date: 2002-02-24T23:22:25+09:00 Subject: Re: duplicate method name On Sun, 24 Feb 2002 12:49:20 GMT, David Alan Black wrote: >Hi -- > >On Sun, 24 Feb 2002, Stefan Schmiedl wrote: > >> Hi Ron. >> >> On Sat, 23 Feb 2002 22:57:41 -0500, >> Ron Jeffries wrote: >> > I just found a case in a test file where i had two tests of the same >> > name. obviously one of them overrode the other and so the first test was >> > "lost". >> > >> > Is there a famous and cool way to avoid this defect? >> >> this is not a defect, it is a feature. >> >> you could do the LaTeX thingy (\newcommand vs. \def) >> and define a method which checks if the current class >> already has the method and then issue a warning or whatever. > >Ruby already does that for you, if you run under '-w': > >$ ruby -we 'class X; def x;end; def x;end; end' >-e:1: warning: discarding old x This is nearly good except that runit doesn't compile clean and -w whines about a bunch of other stuff. Of course there's something to be said for a clean compile. Here's one I don't understand: class Object def meth(arg) return arg*2 end end meth(2).meth (2) The warning is: C:\Data\Ruby\Sets\workspace.rb:10: warning: meth (...) interpreted as method call And the fix is not to space after the second meth. What else could .meth mean at that point? What mistake is it warning me about? Thanks, Ronald E Jeffries http://www.XProgramming.com http://www.objectmentor.com I'm giving the best advice I have. You get to decide whether it's true for you.