diff options
author | Jeremy Evans <[email protected]> | 2020-06-01 15:54:47 -0700 |
---|---|---|
committer | Jeremy Evans <[email protected]> | 2020-06-18 08:22:40 -0700 |
commit | b6d6b896159390014020caac69fa465029af5460 (patch) | |
tree | 174526655d9b2e690822e4ba1c925c158a0e1202 /test/ruby/test_refinement.rb | |
parent | 95dc9c07f3a895f45cfb5dab235cd78f157a9e51 (diff) |
Allow refining a frozen class
Doing so modifies the class's method table, but not in a way that should
be detectable from Ruby, so it may be safe to avoid checking if the
class is frozen.
Fixes [Bug #11669]
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/3175
Diffstat (limited to 'test/ruby/test_refinement.rb')
-rw-r--r-- | test/ruby/test_refinement.rb | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/test/ruby/test_refinement.rb b/test/ruby/test_refinement.rb index 51231bd56c..dd443b7945 100644 --- a/test/ruby/test_refinement.rb +++ b/test/ruby/test_refinement.rb @@ -2405,6 +2405,39 @@ class TestRefinement < Test::Unit::TestCase end end + def test_refine_frozen_class + singleton_class.instance_variable_set(:@x, self) + class << self + c = Class.new do + def foo + :cfoo + end + end + foo = Module.new do + refine c do + def foo + :rfoo + end + end + end + using foo + @x.assert_equal(:rfoo, c.new.foo) + c.freeze + foo.module_eval do + refine c do + def foo + :rfoo2 + end + def bar + :rbar + end + end + end + @x.assert_equal(:rfoo2, c.new.foo) + @x.assert_equal(:rbar, c.new.bar, '[ruby-core:71391] [Bug #11669]') + end + end + private def eval_using(mod, s) |