Skip to content

Kernel#__method__ within a proc returns incorrect value after method definition #2212

@gdeoliveira

Description

@gdeoliveira

When defining more than one method within a class using a proc that returns __method__ all methods will return the symbol representing the last defined method:

DEFINITION = proc { __method__ }

class C
  define_method :one, DEFINITION
  define_method :two, DEFINITION
end

o = C.new

puts o.one  #=> :two (in MRI this returns :one)
puts o.two  #=> :two

Casting DEFINITION into a code block during the method's definition seems to be working correctly though:

class C
  define_method :one, &DEFINITION
  define_method :two, &DEFINITION
end

o = C.new

puts o.one  #=> :one
puts o.two  #=> :two

A lengthier description of the problem can be found at this post in Stack Overflow.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions