Skip to content

import_methods doesn't allow calling another refined method #8876

@esotericpig

Description

@esotericpig

Environment Information

  • jruby 10.0.0.1 (3.4.2) 2025-05-07 79cf1e4aec OpenJDK 64-Bit Server VM 21.0.4+7-LTS on 21.0.4+7-LTS +indy +jit [x86_64-linux]
  • Linux x86_64 GNU/Linux

Expected Behavior

The following works on CRuby, but errors on JRuby v9 and v10:

# frozen_string_literal: true

module MyRef
  module MyMethods
    def my_ref_method
      print '1, '
      my_ref_method_2
    end

    def my_ref_method_2
      puts '2'
    end
  end

  refine Module do
    import_methods MyMethods
  end
end

module MyMod
  using MyRef

  # Ruby  => [:my_ref_method, :my_ref_method_2]
  # JRuby => [:my_ref_method_2, :my_ref_method]
  owner = Module.instance_method(:my_ref_method).owner
  puts owner
  puts owner.instance_methods(false).inspect

  # Ruby  => 1, 2
  # JRuby => 1, NameError: undefined local variable or method 'my_ref_method_2' for module MyMod
  my_ref_method
end

Actual Behavior

Can't call my_ref_method_2 inside of my_ref_method in JRuby.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions