Skip to content

Refinements in method bodies aren't activated #3548

@lazyatom

Description

@lazyatom

(Moved from a comment in #1062)

I've hit some strange behaviour trying to use refinements with version 9.0.4.0:

module Refinement
  refine Object do
    def new_method
      'new method!'
    end
  end
end

class Thing
  using Refinement

  p in_class_definition: Object.new.new_method

  def test
    p in_method: Object.new.new_method
  end
end

Thing.new.test

outputs

{:in_class_definition=>"new method!"}
NoMethodError: undefined method `new_method' for #<Object:0xcfa9dbf>
   test at test.rb:15
  <top> at test.rb:19

It seems like there's something amiss with the lexical scoping of the method; in MRI, methods defined with the lexical scope where a refinement is activated can make use of that refinement. Is this expected behaviour in JRuby as of 9.0.4.0?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions