0

I have a Ruby method which is aliased to several alternative names, and within the method, I would like to know which alias has called me.

This posting suggests that I could use __callee__ to get at this information. However, this does not work in my case, since I am in a module and the method is a module method. The following example demonstrates the problem:

module Demo
  extend self
  def f
    puts __callee__
  end
  alias g f
  alias_method :h,:f
end

Demo.f
Demo.g
Demo.h

This outputs

f
f
f

and not

f
g
h

Could someone explain, why it doesn't work, and how I can do it correctly?

UPDATE: From the feedback I got here and also from other developers, this seems to be a bug in Ruby, which was fixed in 2.3.4.

user1934428
  • 19,864
  • 7
  • 42
  • 87

0 Answers0