Unexpected value of __callee__ when including a module – is this a Ruby bug?

后端 未结 2 1085
孤独总比滥情好
孤独总比滥情好 2021-01-08 01:34

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

相关标签:
2条回答
  • 2021-01-08 01:56

    You can see the difference between __callee__ and __method__ in Ruby's Kernel module.

    The difference is the calls prev_frame_callee() and prev_frame_func(), respectively. I found these function definitions at http://rxr.whitequark.org/mri/source/eval.c

    In short, Foo and Bar are immediately calling the aliased methods foo and bar (which are names for xxx), while Baz has to find Mod and call xxx from Mod. __method__ looks for the original called method's id, while __callee__ looks for the closest called method's id to the __callee__ call. This is better seen in eval.c at lines 848 to 906: look for the difference in the two methods on the return calls similar to <something> -> called_id vs <something> -> def->original_id.

    Also, if you look at the Kernel from version 1.9.3, you will see that the two methods originally were the same. So, at some point, there was a purposeful change between the two.

    0 讨论(0)
  • 2021-01-08 02:13

    This was a bug, and it was closed 3 days ago with this note:

    Seems fixed by r56592.

    0 讨论(0)
提交回复
热议问题