Unexpected value of __callee__ when including a module – is this a Ruby bug?
<p>When invoked via a method created by <code>alias_method</code>, <code>__callee__</code> ignores the name of the old method (here <code>xxx</code>) and returns the name of the new method, as below:</p>

<pre><code>class Foo
  def xxx() __callee__ end
  alias_method :foo, :xxx
end

Foo.new.foo # =&gt; :foo
</code></pre>

<p>This behavior holds even when <code>xxx</code> is inherited from a superclass:</p>

<pre><code>class Sup
  def xxx() __callee__ end
end

class Bar &lt; Sup
  alias_method :bar, :xxx
end

Bar.new.bar # =&gt; :bar
</code></pre>

<p>Given both of the above, I would expect that the same behavior would hold when <code>xxx</code> is included via a module. However, that is not the case:</p>

<pre><code>module Mod
  def xxx() __callee__ end
end

class Baz
  include Mod
  alias_method :baz, :xxx
end

Baz.new.baz # =&gt; :xxx
</code></pre>

<p>I expect the return value to be <code>:baz</code>, not <code>:xxx</code>.</p>

<hr>

<p>The above code was executed using Ruby 2.3.1p112. Is this a bug in the implementation of <code>__callee__</code>? Or maybe of <code>alias_method</code>? And if not, can anyone explain why module inclusion behaves differently?</p>

<hr>

<p><strong>UPDATE 1</strong></p>

<p>I've <a href="https://bugs.ruby-lang.org/issues/12058" rel="nofollow">posted this to the Ruby bug tracker</a> to try to stir up an answer.</p>

<hr>

<p><strong>UPDATE 2</strong></p>

<p>Apparently, I'm <a href="https://bugs.ruby-lang.org/issues/11964" rel="nofollow">not the only one</a> to be surprised by this issue. I wonder whether <a href="https://bugs.ruby-lang.org/projects/ruby-trunk/repository/revisions/50728" rel="nofollow">Revision 50728</a> (which was meant to solve <a href="https://bugs.ruby-lang.org/issues/11046" rel="nofollow">Bug 11046: <em><code>__callee__</code> returns incorrect method name in orphan proc</em></a>) might be related.</p>