Opening a class body doesn't reset the value of __method__ #1402

rf- opened this Issue Jan 14, 2014 · 4 comments


None yet

4 participants

rf- commented Jan 14, 2014
def foo
  eval "class Bar; p __method__; end"


On MRI 2.0.0 and 1.9.3, this prints nil. On JRuby 1.7.9, it prints :foo.

Obviously this is kind of a crazy edge case, but it does cause problems for Pry.

headius commented Jan 14, 2014

Oh Pry, you so crazy.

headius commented Jan 14, 2014

It appears we have never set a method name on the current frame for class and module bodies. When entering a class or module, we simply clone the previous call's frame and do not clear the name therein. That causes method, callee, caller, and others to show the outer method's name.

I believe this is special-cased logic, however. Kernel#caller does show a name, albeit one appropriate to a class:

 $ rvm ruby-2.1 do ruby -e "class Foo; p caller(0)[0]; end"
"-e:1:in `<class:Foo>'"

The fact that method and callee return nil indicates they're specializing that logic for when the surrounding frame is a class.

@headius headius closed this in a049d87 Jan 14, 2014

@headius this fix broke master and jruby-1_7.

@BanzaiMan BanzaiMan reopened this Jan 16, 2014
headius commented Jan 17, 2014

The issue was a bad test in test_trace_func. It didn't pass on MRI either. 3e5496f

@headius headius closed this Jan 17, 2014
@enebo enebo added this to the JRuby 1.7.11 milestone Feb 21, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment