inheritance - Unexpected value of __callee__ when including a module – is this a Ruby bug? -
when invoked via method created alias_method, __callee__ ignores name of old method (here xxx) , returns name of new method, below:
class foo def xxx() __callee__ end alias_method :foo, :xxx end foo.new.foo # => :foo this behavior holds when xxx inherited superclass:
class sup def xxx() __callee__ end end class bar < sup alias_method :bar, :xxx end bar.new.bar # => :bar given both of above, expect same behavior hold when xxx included via module. however, not case:
module mod def xxx() __callee__ end end class baz include mod alias_method :baz, :xxx end baz.new.baz # => :xxx i expect return value :baz, not :xxx.
the above code executed using ruby 2.3.1p112. bug in implementation of __callee__? or maybe of alias_method? , if not, can explain why module inclusion behaves differently?
update 1
i've posted ruby bug tracker try stir answer.
update 2
apparently, i'm not one surprised issue. wonder whether revision 50728 (which meant solve bug 11046: __callee__ returns incorrect method name in orphan proc) might related.
you can see difference between __callee__ , __method__ in ruby's kernel module.
the difference calls prev_frame_callee() , prev_frame_func(), respectively. found these function definitions @ http://rxr.whitequark.org/mri/source/eval.c
in short, foo , bar calling aliased methods foo , bar (which names xxx), while baz has find mod , call xxx mod. __method__ looks original called method's id, while __callee__ looks closest called method's id __callee__ call. better seen in eval.c @ lines 848 906: difference in 2 methods on return calls similar <something> -> called_id vs <something> -> def->original_id.
also, if @ kernel version 1.9.3, see 2 methods same. so, @ point, there purposeful change between two.
Comments
Post a Comment