# I thought frozen objects could not be unfrozen later

**URL:** <https://www.ruby-forum.com/t/i-thought-frozen-objects-could-not-be-unfrozen-later/176879>\
**Category:** Rails\
**Created:** [October 7, 2009, 3:09pm UTC](https://www.ruby-forum.com/t/i-thought-frozen-objects-could-not-be-unfrozen-later/176879 "2009-10-07T15:09:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jasongarber](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/977dab/32.png) [@jasongarber](https://www.ruby-forum.com/u/jasongarber)\
**Post date:** [October 7, 2009, 3:09pm UTC](https://www.ruby-forum.com/t/i-thought-frozen-objects-could-not-be-unfrozen-later/176879/1 "2009-10-07T15:09:02Z")

</div>

In The ActiveSupport memory\_store.rb

@@@  
def write(name, value, options = nil)  
super  
@data[name] = (value.duplicable? ? value.dup : value).freeze  
end  
@@@

This function freezes everything that gets written, according to the  
ruby doc once an object is frozen it cannot be unfrozen later:  
[http://www.ruby-doc.org/core/classes/Object.html#M000356](http://www.ruby-doc.org/core/classes/Object.html#M000356)

so when I read an object from cache

@@@  
def read(name, options = nil)  
super  
@data[name]  
end  
@@@

how am I able to then write to it since its been frozen? Sorry I  
really don’t get this and been trying to understand it since the patch  
was posted.

Thanks

---

<div class="post-metadata">

**Author:** ![jasongarber](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/977dab/32.png) [@jasongarber](https://www.ruby-forum.com/u/jasongarber)\
**Post date:** [October 21, 2009, 12:00pm UTC](https://www.ruby-forum.com/t/i-thought-frozen-objects-could-not-be-unfrozen-later/176879/2 "2009-10-21T12:00:55Z")

</div>

anyone?

---

<div class="post-metadata">

**Author:** ![jasongarber](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/977dab/32.png) [@jasongarber](https://www.ruby-forum.com/u/jasongarber)\
**Post date:** [October 21, 2009, 12:32pm UTC](https://www.ruby-forum.com/t/i-thought-frozen-objects-could-not-be-unfrozen-later/176879/3 "2009-10-21T12:32:32Z")

</div>

On Wed, Oct 21, 2009 at 2:43 AM, codex1 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > ```
> > end
> > super
> > @data[name]
> > end
> > 
> > ```
> > 
> > @@@
> > 
> > how am I able to then write to it since its been frozen? Sorry I  
> > really don’t get this and been trying to understand it since the patch  
> > was posted.
> > 
> > Thanks

Where’s the actual test case that invalidates this code?

-Conrad

---

<div class="post-metadata">

**Author:** ![jasongarber](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/977dab/32.png) [@jasongarber](https://www.ruby-forum.com/u/jasongarber)\
**Post date:** [October 21, 2009, 12:44pm UTC](https://www.ruby-forum.com/t/i-thought-frozen-objects-could-not-be-unfrozen-later/176879/4 "2009-10-21T12:44:15Z")

</div>

On Wed, Oct 21, 2009 at 3:31 AM, Conrad T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > > ```
> > > super
> > > @data[name] = (value.duplicable? ? value.dup : value).freeze
> > > end
> > > 
> > > ```
> > > 
> > > @@@

The above is freezing the value and not the container, @data, for the  
value.  
You can simply try this for yourself using irb.

-Conrad
