From: "tadf (tadayoshi funaba)" Date: 2012-06-03T10:32:35+09:00 Subject: [ruby-core:45397] [ruby-trunk - Bug #6538][Closed] Mutability of Rational and Complex Issue #6538 has been updated by tadf (tadayoshi funaba). Status changed from Assigned to Closed anyway forbade it. this is not a magic. but this trick seems also effective to others. > r = Random.new #=> # > a = r.marshal_dump #=> [...] > r.freeze #=> # > r.frozen? #=> true > (0..10).map{r.rand}.to_a #=> [0.31439277627295725, 0.22940914020883507, 0.1255127954343639, 0.22394641311330976, 0.5371394957199308, 0.6576211090277115, 0.7280552862872753, 0.4931093631805644, 0.6286785684826635, 0.6649446272706543, 0.32721416961292293] > r.marshal_load(a) #=> # > (0..10).map{r.rand}.to_a #=> [0.31439277627295725, 0.22940914020883507, 0.1255127954343639, 0.22394641311330976, 0.5371394957199308, 0.6576211090277115, 0.7280552862872753, 0.4931093631805644, 0.6286785684826635, 0.6649446272706543, 0.32721416961292293] ---------------------------------------- Bug #6538: Mutability of Rational and Complex https://bugs.ruby-lang.org/issues/6538#change-26982 Author: marcandre (Marc-Andre Lafortune) Status: Closed Priority: Low Assignee: tadf (tadayoshi funaba) Category: core Target version: ruby -v: r35875 I hesitated to report this, but there is a "hole" in the immutability of Rational & Complex: r = Rational(0) # Rationals are immutable r.freeze # but let's be certain and freeze it! magic_trick(r) # r is now changed: r # => (1/42) The same thing occurs with Complex. I've left out the definition of `magic_trick` for anyone who wants to try and figure it out, but it's here: http://pastie.org/4016117 Is this worth fixing? -- http://bugs.ruby-lang.org/