Project

General

Profile

Actions

Bug #8261

closed

module_function for methods of same name

Added by manveru (Michael Fellinger) over 11 years ago. Updated over 11 years ago.

Status:
Rejected
Assignee:
-
Target version:
ruby -v:
ruby 2.0.0p0 (2013-02-24 revision 39474) [x86_64-linux]
Backport:
[ruby-core:54223]

Description

This affects all versions from 1.8 to 2.0 I have tested.

I'd expect all three examples below to have the same output, but not only does the example with module_function end up with a private instance method, it also has the wrong one.

If the name of the method is different, it behaves as one would expect, this only happens if the methods have the same name.

module A
def a
1
end

module_function

def a
2
end
end

class X
include A
end

module B
def b
1
end

def self.b
2
end
end

class Y
include B
end

module C
def c
1
end

class << self
def c
2
end
end
end

class Z
include C
end

p [A.a, X.new.send(:a)]

=> [2, 2]

p [B.b, Y.new.b]

=> [2, 1]

p [C.c, Z.new.c]

=> [2, 1]

Updated by nobu (Nobuyoshi Nakada) over 11 years ago

  • Status changed from Open to Rejected

Correct behavior.

Updated by marcandre (Marc-Andre Lafortune) over 11 years ago

Right. Unlike private, protected, public, the method module_function called with no arguments does nothing.

Please refer to the doc http://ruby-doc.org/core-2.0/Module.html#method-i-module_function vs http://ruby-doc.org/core-2.0/Module.html#method-i-private

Actions

Also available in: Atom PDF

Like0
Like0Like0