1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Support obj.clone(freeze: true) for freezing clone

This freezes the clone even if the receiver is not frozen.  It
is only for consistency with freeze: false not freezing the clone
even if the receiver is frozen.

Because Object#clone is now partially implemented in Ruby and
not fully implemented in C, freeze: nil must be supported to
provide the default behavior of only freezing the clone if the
receiver is frozen.

This requires modifying delegate and set, to set freeze: nil
instead of freeze: true as the keyword parameter for
initialize_clone.  Those are the two libraries in stdlib that
override initialize_clone.

Implements [Feature #16175]
This commit is contained in:
Jeremy Evans 2019-09-23 16:03:15 -07:00
parent 095e9f57af
commit 4f7b435c95
Notes: git 2020-03-23 01:30:39 +09:00
6 changed files with 78 additions and 34 deletions

View file

@ -37,11 +37,17 @@ describe "Kernel#clone" do
o3.frozen?.should == true
end
it 'takes an option to copy freeze state or not' do
@obj.clone(freeze: true).frozen?.should == false
ruby_version_is '2.8' do
it 'takes an freeze: true option to frozen copy' do
@obj.clone(freeze: true).frozen?.should == true
@obj.freeze
@obj.clone(freeze: true).frozen?.should == true
end
end
it 'takes an freeze: false option to not return frozen copy' do
@obj.clone(freeze: false).frozen?.should == false
@obj.freeze
@obj.clone(freeze: true).frozen?.should == true
@obj.clone(freeze: false).frozen?.should == false
end