Why have you ever used Object # clone on a frozen object?

Okay, so just out of curiosity, is there a reason why you would ever want to use Object#cloneon a frozen object? As far as I understand, the only reason for using Object#dupit Object#cloneis to get a second copy of an existing object so that you can change it without changing the original. But it Object#clonecopies the frozen state of the object, and you cannot change the frozen objects, so is there any reason why you would ever want to use it in this context?

And according to the corresponding note, if there is no precedent, is there a reason for this?

f = "Some string"
f.frozen? #=> false
f.freeze
f.frozen? #=> true
f2 = f.clone
f2.frozen? #=> true
f2.equal? f #=> false
# Why bother? You can't change f or f2 anyway, so
# why even copy it at all?
+4
source share
1 answer

( ) .clone , , .

, , , , .clone, . , .clone, ( dup ). , - .

, , Ruby, .clone . DSL, , .clone d , , Sinatra, Rails, Grape ..

. , , . DSL, . , , .clone .

+4

Source: https://habr.com/ru/post/1543587/


All Articles