Skip to content

Refinements: method can't use other methods from refinement #5545

@HoneyryderChuck

Description

@HoneyryderChuck

Environment

Provide at least:

  • JRuby version (jruby -v) and command line (flags, JRUBY_OPTS, etc): 9.2.5.0
  • Operating system and platform (e.g. uname -a)

Expected Behavior

I'd expect to reuse methods from a refinement within the same refinement.

module Ext
  refine Array do
    def a
      puts "a"
    end
    def b
      a
      puts "b"
    end
  end
end

using Ext
[].b #=> expects "a" then "b"

Actual Behavior

In reality, a can't be found by b.

Traceback (most recent call last):
        8: from /Users/tiagocardoso/.rubies/jruby-9.2.5.0/bin/irb:13:in `<main>'
        7: from org/jruby/RubyKernel.java:1181:in `catch'
        6: from org/jruby/RubyKernel.java:1181:in `catch'
        5: from org/jruby/RubyKernel.java:1415:in `loop'
        4: from org/jruby/RubyKernel.java:1046:in `eval'
        3: from (irb):12:in `evaluate'
        2: from (irb):14:in `<module:Bang>'
        1: from (irb):7:in `b'
NameError (undefined local variable or method `a' for []:Array
Did you mean?  at)

This works in CRuby since version 2.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions