diff options
author | Jeremy Evans <code@jeremyevans.net> | 2019-08-25 21:11:46 -0700 |
---|---|---|
committer | Jeremy Evans <code@jeremyevans.net> | 2020-01-03 20:13:09 -0800 |
commit | 04eb7c7e462d1fcbab9efc7022c1b43636ab878a (patch) | |
tree | 025cb1f1e10736e9c37eb991a8c4cdb1931d4ff2 /test/test_delegate.rb | |
parent | 0eeed5bcc5530edb0af2af2ccff09d067c59e8f9 (diff) |
Call initialize_clone with freeze: false if clone called with freeze: false
This makes it possible to initialize_clone to correctly not freeze
internal state if the freeze: false keyword is passed to clone.
If clone is called with freeze: true or no keyword, do not pass
a second argument to initialize_clone to keep backwards
compatibility.
This makes it so that external libraries that override
initialize_clone but do not support the freeze keyword will fail
with ArgumentError if passing freeze: false to clone. I think that
is better than the current behavior, which succeeds but results in
an unfrozen object with frozen internals.
Fix related issues in set and delegate in stdlib.
Fixes [Bug #14266]
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/2816
Diffstat (limited to 'test/test_delegate.rb')
-rw-r--r-- | test/test_delegate.rb | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/test/test_delegate.rb b/test/test_delegate.rb index 303cd16897..80bf41638a 100644 --- a/test/test_delegate.rb +++ b/test/test_delegate.rb @@ -50,6 +50,21 @@ class TestDelegateClass < Test::Unit::TestCase assert_equal(SimpleDelegator,simple.clone.class) end + def test_simpledelegator_clone + simple=SimpleDelegator.new([]) + simple.freeze + + clone = simple.clone + assert_predicate clone, :frozen? + assert_predicate clone.__getobj__, :frozen? + assert_equal true, Kernel.instance_method(:frozen?).bind(clone).call + + clone = simple.clone(freeze: false) + assert_not_predicate clone, :frozen? + assert_not_predicate clone.__getobj__, :frozen? + assert_equal false, Kernel.instance_method(:frozen?).bind(clone).call + end + class Object def m :o |