diff options
author | Jeremy Evans <code@jeremyevans.net> | 2019-09-23 16:03:15 -0700 |
---|---|---|
committer | Jeremy Evans <code@jeremyevans.net> | 2020-03-22 09:30:07 -0700 |
commit | 4f7b435c955792af780fe9e94f98d3dde839e056 (patch) | |
tree | e6d3a5433aca7a48b79eba02056cc905dc3c88c4 /kernel.rb | |
parent | 095e9f57af30fc286ba66557d86f080003ab6d5a (diff) | |
download | ruby-4f7b435c955792af780fe9e94f98d3dde839e056.tar.gz |
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]
Diffstat (limited to 'kernel.rb')
-rw-r--r-- | kernel.rb | 10 |
1 files changed, 5 insertions, 5 deletions
@@ -1,13 +1,13 @@ module Kernel # # call-seq: - # obj.clone(freeze: true) -> an_object + # obj.clone(freeze: nil) -> an_object # # Produces a shallow copy of <i>obj</i>---the instance variables of # <i>obj</i> are copied, but not the objects they reference. - # #clone copies the frozen (unless +:freeze+ keyword argument is - # given with a false value) state of <i>obj</i>. See - # also the discussion under Object#dup. + # #clone copies the frozen value state of <i>obj</i>, unless the + # +:freeze+ keyword argument is given with a false or true value. + # See also the discussion under Object#dup. # # class Klass # attr_accessor :str @@ -23,7 +23,7 @@ module Kernel # behavior will be documented under the #+initialize_copy+ method of # the class. # - def clone(freeze: true) + def clone(freeze: nil) __builtin_rb_obj_clone2(freeze) end end |