From: "marcandre (Marc-Andre Lafortune)" Date: 2012-06-03T12:41:27+09:00 Subject: [ruby-core:45402] [ruby-trunk - Bug #6538][Open] Mutability of Rational and Complex Issue #6538 has been updated by marcandre (Marc-Andre Lafortune). Status changed from Closed to Open Assignee deleted (tadf (tadayoshi funaba)) I see that this trick won't work if it's frozen after your commit, but the the freeze part was just more fun, sorry. It's the immutability of Rational and Complex that is at stake here. r = Rational(0) magic_trick(r) r # => (1/42) This should not be possible, ideally, no? Rationals and Complex are expected to be immutable. Also, not all logic is applied to marshal_load. There are all sorts of nasty tricks that one could play with this. c = Complex(1) r = Rational(0).marshal_load([1, c]) c.marshal_load([0,0]) r # => (1/(0+0i)) The fix would be ugly. Complex and Rational should not have marshal_load/dump methods. Using _load and _dump would break marshal format accross versions, so Marshal.{load|dump} would need to make special cases for Complex and Rational. ---------------------------------------- Bug #6538: Mutability of Rational and Complex https://bugs.ruby-lang.org/issues/6538#change-26984 Author: marcandre (Marc-Andre Lafortune) Status: Open Priority: Low Assignee: 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/