Project

General

Profile

Actions

Bug #1533

closed

Inconsistency Between Hash#to_s and Hash#inspect

Bug #1533: Inconsistency Between Hash#to_s and Hash#inspect

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

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 1.9.1p129 (2009-05-12 revision 23412) [i686-linux]
Backport:
[ruby-core:23601]

Description

=begin
There is an inconsistency between Hash#to_s and Hash#inspect with respect to recursive data structures. For example:

 $ ruby -v -e 'x={};x[0]=x;p x.to_s'
 ruby 1.9.1p129 (2009-05-12 revision 23412) [i686-linux]
 "{0=>{0=>{...}}}"

 $ ruby -v -e 'x={};x[0]=x;p x.inspect'
 ruby 1.9.1p129 (2009-05-12 revision 23412) [i686-linux]
 "{0=>{...}}"

 $ ruby1.8 -v -e 'x={};x[0]=x;p x.to_s'
 ruby 1.8.7 (2008-08-11 patchlevel 72) [i486-linux]
 "0{...}"


 $ ruby1.8 -v -e 'x={};x[0]=x;p x.inspect'
 ruby 1.8.7 (2008-08-11 patchlevel 72) [i486-linux]
 "{0=>{...}}"

ujihisa noticed that it was caused by a similar issue to the bug he reported in http://redmine.ruby-lang.org/issues/show/1427 . He produced a patch in less time than it took me to type this report, which I have attached. He provides the following demonstration of its result:

 #!./ruby -v
 # ruby 1.9.2dev (2009-05-28 trunk 23601) [i386-darwin9.7.0]
 x = {}
 x[0] = x
 puts x.to_s #=> {0=>{0=>{...}}}
 puts x.inspect #=> {0=>{...}}

 # After the patch:

 puts x.to_s #=> {0=>{...}}
 puts x.inspect #=> {0=>{...}}

Thanks!
=end


Files

hash.c-to_s.patch (533 Bytes) hash.c-to_s.patch runpaint (Run Paint Run Run), 05/29/2009 06:15 AM

Updated by nobu (Nobuyoshi Nakada) over 16 years ago Actions #1

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

=begin
Applied in changeset r23604.
=end

Actions

Also available in: PDF Atom