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

Refinement with super vs. inheritance #5221

Closed
palkan opened this issue Jun 17, 2018 · 3 comments
Closed

Refinement with super vs. inheritance #5221

palkan opened this issue Jun 17, 2018 · 3 comments
Milestone

Comments

@palkan
Copy link

palkan commented Jun 17, 2018

Environment

  • JRuby version: jruby 9.2.0.0 (2.5.0) 2018-05-24 81156a8 OpenJDK 64-Bit Server VM 25.171-b11 on 1.8.0_171-8u171-b11-1~deb9u1-b11 +jit [linux-x86_64]
  • Operating system and platform: Linux 3971953e9581 4.9.49-moby break script engine #1 SMP Fri Dec 8 13:40:02 UTC 2017 x86_64 GNU/Linux

Expected Behavior

The code below print "foo-o-o" (as in CRuby):

class A
  def foo
    "foo"
  end
end

class B < A; end

module SuperExt
  refine A do
    def foo
      super + "-o-o"
    end
  end
end

using SuperExt

p B.new.foo

Actual Behavior

It doesn't activate the refinement and prints "foo".

When calling on a A class instance works as expected:

class A
  def foo
    "foo"
  end
end

module SuperExt
  refine A do
    def foo
      super + "-o-o"
    end
  end
end

using SuperExt

p A.new.foo #=> "foo-o-o"
@monkstone
Copy link
Contributor

This means that you can't refine Numeric for example:-

module SuperNumeric 
  refine Numeric do
    def degrees
      self * 57.29577951308232
    end

    def radians
      self * 0.017453292519943295
    end
  end
end

using SuperNumeric

puts 45.radians
puts 0.7853981634.degrees

mri ruby:-

0.7853981633974483
45.0000000001462

jruby (9.2.0.0 (2.5.0) 2018-05-24 81156a8 OpenJDK 64-Bit Server VM 25.171-b11 on 1.8.0_171-8u171-b11-0ubuntu0.16.04.1-b11 +jit [linux-x86_64])

NoMethodError: undefined method `radians' for 45:Integer
  <main> at numeric.rb:15

@Envek Envek mentioned this issue Jan 4, 2019
english added a commit to english/rspec-generators that referenced this issue Jan 18, 2019
it doesn't seem to support refinements that use inheritence, see
jruby/jruby#5221
@headius headius added this to the JRuby 9.2.7.0 milestone Feb 26, 2019
@headius
Copy link
Member

headius commented Feb 26, 2019

This is fixed after #5604 and #5627.

@headius
Copy link
Member

headius commented Mar 7, 2019

Both PRs and additional fixes have been merged.

@headius headius closed this as completed Mar 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants