diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2019-07-17 10:35:59 +0900 |
|---|---|---|
| committer | GitHub <[email protected]> | 2019-07-17 10:35:59 +0900 |
| commit | 5eef75b678b41249cf4738ef42889090caea2ab0 (patch) | |
| tree | 774fc0de56002abb3bb2b1c3387ff08f91876d17 /mrblib | |
| parent | 9af3b7c6258de327218dd04e69d76ae68caf17b1 (diff) | |
| parent | d605b72c1d6fa4564a0a5e88535504b6850463b5 (diff) | |
| download | mruby-5eef75b678b41249cf4738ef42889090caea2ab0.tar.gz mruby-5eef75b678b41249cf4738ef42889090caea2ab0.zip | |
Merge pull request #4034 from i110/i110/inspect-recursion
Let inspect recursion do the right thing
Diffstat (limited to 'mrblib')
| -rw-r--r-- | mrblib/array.rb | 12 | ||||
| -rw-r--r-- | mrblib/hash.rb | 10 | ||||
| -rw-r--r-- | mrblib/kernel.rb | 2 |
3 files changed, 10 insertions, 14 deletions
diff --git a/mrblib/array.rb b/mrblib/array.rb index d598efc77..2b080564c 100644 --- a/mrblib/array.rb +++ b/mrblib/array.rb @@ -83,13 +83,15 @@ class Array self end - def _inspect + def _inspect(recur_list) size = self.size return "[]" if size == 0 + return "[...]" if recur_list[self.object_id] + recur_list[self.object_id] = true ary=[] i=0 while i<size - ary<<self[i].inspect + ary<<self[i]._inspect(recur_list) i+=1 end "["+ary.join(", ")+"]" @@ -99,11 +101,7 @@ class Array # # ISO 15.2.12.5.31 (x) def inspect - begin - self._inspect - rescue SystemStackError - "[...]" - end + self._inspect({}) end # ISO 15.2.12.5.32 (x) alias to_s inspect diff --git a/mrblib/hash.rb b/mrblib/hash.rb index 609883ecb..0e2da62e1 100644 --- a/mrblib/hash.rb +++ b/mrblib/hash.rb @@ -186,8 +186,10 @@ class Hash end # internal method for Hash inspection - def _inspect + def _inspect(recur_list) return "{}" if self.size == 0 + return "{...}" if recur_list[self.object_id] + recur_list[self.object_id] = true ary=[] keys=self.keys size=keys.size @@ -204,11 +206,7 @@ class Hash # # ISO 15.2.13.4.30 (x) def inspect - begin - self._inspect - rescue SystemStackError - "{...}" - end + self._inspect({}) end # ISO 15.2.13.4.31 (x) alias to_s inspect diff --git a/mrblib/kernel.rb b/mrblib/kernel.rb index 4700684b6..7c3ea9420 100644 --- a/mrblib/kernel.rb +++ b/mrblib/kernel.rb @@ -40,7 +40,7 @@ module Kernel end # internal method for inspect - def _inspect + def _inspect(_recur_list) self.inspect end |
