Bug #2134: Inspect Output for Rational and Complex
http://redmine.ruby-lang.org/issues/show/2134

Author: Run Paint Run Run
Status: Open, Priority: Low
Category: core
ruby -v: ruby 1.9.2dev (2009-09-11) [i686-linux]

The inspect output of both Rational and Complex does not eval to the original number:

>> Rational(3,5).inspect
=> "(3/5)"
>> Complex(3,5).inspect
=> "(3+5i)"

In [ruby-core:23856] matz explained that the Rational output, at least, is an intentional change "in preparation for Rational literals, which is planned for the future." Then, in [ruby-core:24731], matz wrote that he was no longer considering literals for imaginary numbers. I'm unsure what if any connection these two statements have.

That many objects with a literal syntax produce #inspect output is eval'able to the same object is a particularly useful characteristic, especially for code generation when you don't want Marshal's obfuscation. The changes in question prevent Complex and Rational being serialised in this fashion. In fact, in Rational's case the breakage is more subtle because the #inspect output is valid syntax, so integer division is performed silently:

  eval Rational(7,2).inspect
  => 3

I suppose I have two questions:

1) Are Rational and Complex literals still planned? (If so, could we open a feature ticket to track the progress?)
2) Is it necessary that their #inspect output is changed preemptively?


----------------------------------------
http://redmine.ruby-lang.org