[ruby-core:54223] [ruby-trunk - Bug #8261][Open] module_function for methods of same name

0 views
Skip to first unread message

manveru (Michael Fellinger)

unread,
Apr 12, 2013, 9:54:05 AM4/12/13
to ruby...@ruby-lang.org

Issue #8261 has been reported by manveru (Michael Fellinger).

----------------------------------------
Bug #8261: module_function for methods of same name
https://bugs.ruby-lang.org/issues/8261

Author: manveru (Michael Fellinger)
Status: Open
Priority: Low
Assignee:
Category: core
Target version: current: 2.1.0
ruby -v: ruby 2.0.0p0 (2013-02-24 revision 39474) [x86_64-linux]


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]


--
http://bugs.ruby-lang.org/

nobu (Nobuyoshi Nakada)

unread,
Apr 12, 2013, 11:55:08 AM4/12/13
to ruby...@ruby-lang.org

Issue #8261 has been updated by nobu (Nobuyoshi Nakada).

Status changed from Open to Rejected

Correct behavior.
----------------------------------------
Bug #8261: module_function for methods of same name
https://bugs.ruby-lang.org/issues/8261#change-38496

Author: manveru (Michael Fellinger)
Status: Rejected

marcandre (Marc-Andre Lafortune)

unread,
Apr 12, 2013, 2:58:38 PM4/12/13
to ruby...@ruby-lang.org

Issue #8261 has been updated by marcandre (Marc-Andre Lafortune).


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
----------------------------------------
Bug #8261: module_function for methods of same name
https://bugs.ruby-lang.org/issues/8261#change-38505

Author: manveru (Michael Fellinger)
Status: Rejected
Reply all
Reply to author
Forward
0 new messages