don't print anonymous struct class name

This commit is contained in:
Yukihiro "Matz" Matsumoto
2015-09-23 12:50:52 +09:00
parent 20a4e9ade6
commit 101ec5eb0a
2 changed files with 7 additions and 2 deletions
+6 -1
View File
@@ -47,7 +47,12 @@ if Object.const_defined?(:Struct)
end
def _inspect
str = "#<struct #{self.class.to_s} "
name = self.class.to_s
if name[0] == "#"
str = "#<struct "
else
str = "#<struct #{name} "
end
buf = []
self.each_pair do |k,v|
buf.push [k.to_s + "=" + v._inspect]
+1 -1
View File
@@ -103,7 +103,7 @@ end
assert('struct inspect') do
c = Struct.new(:m1, :m2, :m3, :m4, :m5)
cc = c.new(1,2,3,4,5)
assert_equal "#<struct #{c.inspect} m1=1, m2=2, m3=3, m4=4, m5=5>", cc.inspect
assert_equal "#<struct m1=1, m2=2, m3=3, m4=4, m5=5>", cc.inspect
end
assert('Struct#length, Struct#size') do