Project

General

Profile

Actions

Bug #2134

closed

Inspect Output for Rational and Complex

Added by runpaint (Run Paint Run Run) over 14 years ago. Updated about 13 years ago.

Status:
Rejected
Target version:
-
ruby -v:
ruby 1.9.2dev (2009-09-11) [i686-linux]
Backport:
[ruby-core:25715]

Description

=begin
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?
    =end
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0