Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
HoneyryderChuck opened this Issue Dec 31, 2018 · 3 comments

Comments

Projects
None yet
4 participants
@HoneyryderChuck
Copy link

HoneyryderChuck commented Dec 31, 2018

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

@palkan

This comment has been minimized.

Copy link

palkan commented Jan 6, 2019

Duplicate? #5054

@enebo enebo modified the milestones: JRuby 9.2.6.0, JRuby 9.2.8.0 Jan 9, 2019

@enebo enebo modified the milestones: JRuby 9.2.6.0, JRuby 9.2.7.0 Feb 11, 2019

@headius

This comment has been minimized.

Copy link
Member

headius commented Feb 26, 2019

Fixed by #5627 once it lands, or perhaps the refinement stuff that preceded it.

@headius

This comment has been minimized.

Copy link
Member

headius commented Apr 8, 2019

Fixed for 9.2.7.

[] ~/projects/jruby $ cat blah.rb
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"
[] ~/projects/jruby $ rvm ruby-2.5.3 do ruby blah.rb
a
b

[] ~/projects/jruby $ jruby -v blah.rb
jruby 9.2.7.0-SNAPSHOT (2.5.3) 2019-04-08 2122e9f OpenJDK 64-Bit Server VM 25.202-b08 on 1.8.0_202-b08 +jit [darwin-x86_64]
a
b

@headius headius closed this Apr 8, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.