summaryrefslogtreecommitdiffhomepage
path: root/mrblib/hash.rb
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2014-07-12 23:22:20 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2014-07-12 23:22:20 +0900
commit79fb18445dec95c546b43a98b38b541674f89d93 (patch)
tree7512ae2b05396efad6f79b72c238067c0f75dbd9 /mrblib/hash.rb
parent6137bf9e7148235b9104f74cb189663c06204e90 (diff)
downloadmruby-79fb18445dec95c546b43a98b38b541674f89d93.tar.gz
mruby-79fb18445dec95c546b43a98b38b541674f89d93.zip
rescue SystemStackError that comes from inspecting self-referencing Hashes and Arrays; fix #2461
Diffstat (limited to 'mrblib/hash.rb')
-rw-r--r--mrblib/hash.rb20
1 files changed, 14 insertions, 6 deletions
diff --git a/mrblib/hash.rb b/mrblib/hash.rb
index 9bb146b27..e7c51fb1f 100644
--- a/mrblib/hash.rb
+++ b/mrblib/hash.rb
@@ -192,16 +192,24 @@ class Hash
h
end
- ##
- # Return the contents of this hash as a string.
- #
- # ISO 15.2.13.4.30 (x)
- def inspect
+ # internal method for Hash inspection
+ def _inspect
return "{}" if self.size == 0
"{"+self.map {|k,v|
- k.inspect + "=>" + v.inspect
+ k._inspect + "=>" + v._inspect
}.join(", ")+"}"
end
+ ##
+ # Return the contents of this hash as a string.
+ #
+ # ISO 15.2.13.4.30 (x)
+ def inspect
+ begin
+ self._inspect
+ rescue SystemStackError
+ "{...}"
+ end
+ end
# ISO 15.2.13.4.31 (x)
alias to_s inspect