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
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"
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
This is fixed after #5604 and #5627.
Both PRs and additional fixes have been merged.
Most helpful comment
Both PRs and additional fixes have been merged.