Modules, identical methods and warnings

(Berger, Daniel) #1

Hi all,

I was just thinking about the potential issue of including multiple modules with identical method names. Specifically, I was wondering about the -w switch.

Consider:

class Foo
    attr_reader :test
    def test; end
end

Running this with -w emits, "warning: method redefined; discarding old test".

Now consider:

module Bar
    def test; end
end

module Baz
    def test; end
end

class Foo
    include Bar
    include Baz
end

Shouldn't -w emit a warning in this case? If not, why not? If so, how difficult would it be to implement? And would it have any annoying -w side effects?

Regards,

Dan

(Yukihiro Matsumoto) #2

Hi,

···

In message "Re: Modules, identical methods and warnings" on Thu, 11 Aug 2005 03:07:07 +0900, Daniel Berger <Daniel.Berger@qwest.com> writes:

Now consider:

module Bar
   def test; end
end

module Baz
   def test; end
end

class Foo
   include Bar
   include Baz
end

Shouldn't -w emit a warning in this case? If not, why not? If so, how
difficult would it be to implement? And would it have any annoying -w
side effects?

As Module#ancestors tell you, priority line is Foo - Baz - Bar, you
can/may chain test methods by using super, so that simple error
emission is not good, at least under the current behavior.

              matz.