# Is Set#freeze broken?

**URL:** <https://www.ruby-forum.com/t/is-set-freeze-broken/119811>\
**Category:** Ruby\
**Created:** [November 10, 2007, 8:43pm UTC](https://www.ruby-forum.com/t/is-set-freeze-broken/119811 "2007-11-10T20:43:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vasyl\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/4bbf92/32.png) [@Vasyl\_S](https://www.ruby-forum.com/u/Vasyl_S)\
**Post date:** [November 10, 2007, 8:43pm UTC](https://www.ruby-forum.com/t/is-set-freeze-broken/119811/1 "2007-11-10T20:43:58Z")

</div>

I’ve tried to freeze a Set instance, and it turned out not working:

irb(main):001:0\> require ‘set’  
=\> true  
irb(main):002:0\> x = Set.new [“a”, “b”, “c”]  
=\> #\<Set: {“a”, “b”, “c”}\>  
irb(main):003:0\> x  
=\> #\<Set: {“a”, “b”, “c”}\>  
irb(main):004:0\> x.freeze  
=\> #\<Set: {“a”, “b”, “c”}\>  
irb(main):005:0\> x \<\< “d”  
=\> #\<Set: {“a”, “b”, “c”, “d”}\>

Is this a bug, or it works as designed?

---

<div class="post-metadata">

**Author:** ![Vasyl\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/4bbf92/32.png) [@Vasyl\_S](https://www.ruby-forum.com/u/Vasyl_S)\
**Post date:** [November 10, 2007, 8:53pm UTC](https://www.ruby-forum.com/t/is-set-freeze-broken/119811/2 "2007-11-10T20:53:19Z")

</div>

On Nov 10, 9:43 pm, Vasyl S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I’ve tried to freeze a Set instance, and it turned out not working:

The following fixes the problem:

require ‘set’

# Patch for Set to make freeze work.

class Set  
def freeze  
@hash.freeze  
self  
end  
def frozen?  
@hash.frozen?  
end  
end
