Modules, identical methods and warnings

D

Daniel Berger

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
 
Y

Yukihiro Matsumoto

Hi,

In message "Re: Modules, identical methods and warnings"

|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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,276
Latest member
Sawatmakal

Latest Threads

Top