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