Project

General

Profile

Actions

Bug #1427

closed

Difference between Array#to_s and Array#inspect

Added by ujihisa (Tatsuhiro Ujihisa) over 15 years ago. Updated over 13 years ago.

Status:
Closed
Assignee:
-
Target version:
ruby -v:
ruby 1.9.2dev (2009-04-30 trunk 23312) [i386-darwin9.6.0]
Backport:
[ruby-dev:38362]

Description

=begin
ruby 1.9では通常Array#to_sとArray#inspectは同じ文字列を返しますが、自己再帰する配列に対しては異なる結果を返しています。

ruby 1.9.2dev (2009-04-30 trunk 23312) [i386-darwin9.6.0]

a = [1]
a << a
a.inspect #=> [1, [...]]
a.to_s #=>[1, [1, [...]]]

rb_exec_recursiveのrecursive_checkで、Array#inspectはinspect -> inspectと処理が進んで再帰を判定しますが、Array#to_sはto_s -> inspect -> inspectと処理が進んで判定するため、後者の方が一回多くrb_ary_inspectを呼び出しています。

to_sをinspectのaliasにするパッチを添付します。
=end


Files

alias.patch (639 Bytes) alias.patch ujihisa (Tatsuhiro Ujihisa), 05/01/2009 11:48 PM
Actions #1

Updated by nobu (Nobuyoshi Nakada) over 15 years ago

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

=begin
Applied in changeset r23324.
=end

Actions

Also available in: Atom PDF

Like0
Like0