Project

General

Profile

Actions

Bug #12058

closed

Unexpected value of __callee__ when including a module

Added by jessesielaff (Jesse Sielaff) almost 9 years ago. Updated almost 8 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-darwin15]
[ruby-core:73743]

Description

I noticed a surprising behavior when invoking __callee__ in an aliased method.

When invoked via a method created by alias_method, __callee__ ignores the name of the old method (here xxx) and returns the name of the new method, as below:

class Foo
  def xxx() __callee__ end
  alias_method :foo, :xxx
end

Foo.new.foo # => :foo

This behavior holds even when xxx is inherited from a superclass:

class Sup
  def xxx() __callee__ end
end

class Bar < Sup
  alias_method :bar, :xxx
end

Bar.new.bar # => :bar

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

module Mod
  def xxx() __callee__ end
end

class Baz
  include Mod
  alias_method :baz, :xxx
end

Baz.new.baz # => :xxx

I expect the return value to be :baz, not :xxx.

Is this a bug, or is there an important difference between superclass inheritance and module inclusion that I've failed to grasp here?

Origin: http://stackoverflow.com/questions/35281623/unexpected-value-of-callee-when-including-a-module-is-this-a-ruby-bug


Related issues 1 (0 open1 closed)

Is duplicate of Ruby master - Bug #11964: __callee__ in aliased methods defined in a module returns an incorrect valueClosedko1 (Koichi Sasada)Actions

Updated by jessesielaff (Jesse Sielaff) almost 9 years ago

  • ruby -v changed from 2.3.0p0 to ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-darwin15]
Actions #2

Updated by nobu (Nobuyoshi Nakada) over 8 years ago

  • Is duplicate of Bug #11964: __callee__ in aliased methods defined in a module returns an incorrect value added

Updated by nobu (Nobuyoshi Nakada) over 8 years ago

  • Description updated (diff)
Actions #4

Updated by nobu (Nobuyoshi Nakada) almost 8 years ago

  • Status changed from Open to Closed

Seems fixed by r56592.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0