Is Set#freeze broken?

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?

On Nov 10, 9:43 pm, Vasyl S. [email protected] 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