Quantcast
Channel: How to unfreeze an object in Ruby? - Stack Overflow
Browsing latest articles
Browse All 5 View Live

Answer by Nardo Nykolyszyn for How to unfreeze an object in Ruby?

frozen_object = %w[hello world].freeze frozen_object.concat(['and universe']) # FrozenError (can't modify frozen Array) frozen_object.dup.concat(['and universe']) # ['hello', 'world', 'and universe']

View Article



Answer by Peter Jirak Eldritch for How to unfreeze an object in Ruby?

As noted above copying the variable back into itself also effectively unfreezes the variable. As noted this can be done using the .dup method: var1 = var1.dup This can also be achieved using: var1 =...

View Article

Answer by Stefan for How to unfreeze an object in Ruby?

No, according to the documentation for Object#freeze: There is no way to unfreeze a frozen object. The frozen state is stored within the object. Calling freeze sets the frozen state and thereby...

View Article

Answer by ndnenkov for How to unfreeze an object in Ruby?

Yes and no. There isn't any direct way using the standard API. However, with some understanding of what #freeze? does, you can work around it. Note: everything here is implementation details of MRI's...

View Article

How to unfreeze an object in Ruby?

In Ruby, there is Object#freeze, which prevents further modifications to the object: class Kingdom attr_accessor :weather_conditions end arendelle = Kingdom.new arendelle.frozen? # => false...

View Article

Browsing latest articles
Browse All 5 View Live


Latest Images