Issue #16175 has been updated by jeremyevans0 (Jeremy Evans).

Backport deleted (2.5: UNKNOWN, 2.6: UNKNOWN)
Subject changed from Object#clone(freeze: true) to Make Object#clone(freeze: true) return frozen clone even if receiver is not frozen
Tracker changed from Bug to Feature

The `freeze: false` option was intended to be: "do not freeze clone if receiver is already frozen". The `Object#clone` documentation states: "#clone copies the frozen (unless `:freeze` keyword argument is given with a false value) and tainted state of <i>obj</i>".  The behavior when `freeze: true` is provided is therefore unspecified, and therefore, I do not think this should be considered a bug.

The reason `freeze: false` was introduced is because you previously could not use `clone` with frozen objects with singleton classes/extended modules and keep the ability to modify copies of the frozen objects.  Adding `freeze: false` made something previously impossible in Ruby possible.  Adding `freeze: true` for consistency doesn't enable new behavior, as you can use `clone.freeze` instead of `clone(freeze: true)`.  That being said, I'm not opposed to `freeze: true` being supported.

----------------------------------------
Feature #16175: Make Object#clone(freeze: true) return frozen clone even if receiver is not frozen
https://bugs.ruby-lang.org/issues/16175#change-81649

* Author: zverok (Victor Shepelev)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
In #12300, the new keyword `freeze:` was introduced, allowing this:

```ruby
h = {}.freeze
h.clone.frozen?
# => true
h.clone(freeze: false).frozen?
# => false
```
Though, it turns to me that behavior is not symmetric:
```ruby
h = {}
h.frozen?
# => false
h.clone.frozen?
# => false
h.clone(freeze: true).frozen?
# => false -- I expected true here!
```
I wonder, if it is "by design" and should be addressed in docs, or just an implementation inconsistency that can be fixed?



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>