From d9feed6703e6db86334497e90e9751a974545055 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Tue, 1 Apr 2014 14:31:39 +0900 Subject: move Array#inspect implementation to mrblib/array.rb --- mrblib/array.rb | 11 +++++++++++ mrblib/hash.rb | 1 + 2 files changed, 12 insertions(+) (limited to 'mrblib') diff --git a/mrblib/array.rb b/mrblib/array.rb index a7f172879..718553e83 100644 --- a/mrblib/array.rb +++ b/mrblib/array.rb @@ -84,6 +84,17 @@ class Array self end + ## + # Private method for Array creation. + # + # ISO 15.2.12.5.31 (x) + def inspect + return "[]" if self.size == 0 + "["+self.map{|x|x.inspect}.join(", ")+"]" + end + # ISO 15.2.12.5.32 (x) + alias to_s inspect + ## # Delete element with index +key+ def delete(key, &block) diff --git a/mrblib/hash.rb b/mrblib/hash.rb index 74d3d0534..d15fa434e 100644 --- a/mrblib/hash.rb +++ b/mrblib/hash.rb @@ -142,6 +142,7 @@ class Hash k.inspect + "=>" + v.inspect }.join(", ")+"}" end + # ISO 15.2.13.4.31 (x) alias to_s inspect # 1.8/1.9 Hash#reject! returns Hash; ISO says nothing. -- cgit v1.2.3