[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Is Set#freeze broken?

Vasyl Smirnov

11/10/2007 7:43:00 PM

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?


1 Answer

Vasyl Smirnov

11/10/2007 7:53:00 PM

0

On Nov 10, 9:43 pm, Vasyl Smirnov <vasyl.smir...@gmail.com> 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