From: s@... (Stefan Schmiedl) Date: 2002-02-24T16:22:08+09:00 Subject: Re: duplicate method name 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. > irb irb(main):001:0> class A irb(main):002:1> def hi; end irb(main):003:1> p self.public_methods irb(main):004:1> end ["new", "superclass", "<", "private_class_method", "private_instance_methods", "included_modules", ">", "public_class_method", "const_defined?", "protected_instance_methods", "to_s", "<=>", "method_defined?", "const_set", "public_instance_methods", "===", "instance_method", "class_eval", "class_variables", "const_get", "instance_methods", "ancestors", "dup", ">=", "<=", "module_eval", "constants", "name", "clone", "==", "singleton_methods", "tainted?", "eql?", "method", "methods", "nil?", "is_a?", "instance_of?", "class", "instance_variables", "send", "frozen?", "__id__", "__send__", "=~", "hash", "protected_methods", "untaint", "respond_to?", "public_methods", "taint", "equal?", "kind_of?", "inspect", "display", "instance_eval", "to_a", "type", "freeze", "id", "extend", "private_methods"]nil # dang, got class methods once again irb(main):005:0> class B irb(main):006:1> def hi; end irb(main):007:1> p self.public_instance_methods irb(main):008:1> end ["hi"] nil irb(main):009:0> so public_instance_methods, member? and eval should get you going. if you also want to include methods defined in some superclass, use irb(main):024:0> class C < B irb(main):025:1> p self.ancestors.collect { |cl| cl.public_instance_methods }.flatten irb(main):026:1> end ["hi", "==", "===", "singleton_methods", "tainted?", "eql?", "method", "methods", "dup", "nil?", "is_a?", "instance_of?", "to_s", "class", "instance_variables", "send", "frozen?", "__id__", "__send__", "=~", "hash", "protected_methods", "untaint", "respond_to?", "public_methods", "taint", "equal?", "clone", "kind_of?", "inspect", "display", "instance_eval", "to_a", "type", "freeze", "id", "extend", "private_methods"] ain't that cool ... s. -- Stefan Schmiedl EDV-Beratung, Programmierung, Schulung Loreleystr. 5, 94315 Straubing, Germany Tel. (0 94 21) 74 01 06 Public Key: http://xss.de/stefan.public shhhh ... I can't hear my code! > > 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.