summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJeremy Evans <code@jeremyevans.net>2019-08-25 21:11:46 -0700
committerJeremy Evans <code@jeremyevans.net>2020-01-03 20:13:09 -0800
commit04eb7c7e462d1fcbab9efc7022c1b43636ab878a (patch)
tree025cb1f1e10736e9c37eb991a8c4cdb1931d4ff2 /lib
parent0eeed5bcc5530edb0af2af2ccff09d067c59e8f9 (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 'lib')
-rw-r--r--lib/delegate.rb4
-rw-r--r--lib/set.rb4
2 files changed, 4 insertions, 4 deletions
diff --git a/lib/delegate.rb b/lib/delegate.rb
index 8c176dc82c..0bbe211a05 100644
--- a/lib/delegate.rb
+++ b/lib/delegate.rb
@@ -211,8 +211,8 @@ class Delegator < BasicObject
end
end
- def initialize_clone(obj) # :nodoc:
- self.__setobj__(obj.__getobj__.clone)
+ def initialize_clone(obj, freeze: true) # :nodoc:
+ self.__setobj__(obj.__getobj__.clone(freeze: freeze))
end
def initialize_dup(obj) # :nodoc:
self.__setobj__(obj.__getobj__.dup)
diff --git a/lib/set.rb b/lib/set.rb
index e7d1be4f9f..684115539b 100644
--- a/lib/set.rb
+++ b/lib/set.rb
@@ -137,9 +137,9 @@ class Set
end
# Clone internal hash.
- def initialize_clone(orig)
+ def initialize_clone(orig, freeze: true)
super
- @hash = orig.instance_variable_get(:@hash).clone
+ @hash = orig.instance_variable_get(:@hash).clone(freeze: freeze)
end
def freeze # :nodoc: