【发布时间】:2014-05-25 14:59:04
【问题描述】:
为什么当我对内置类进行子类化时,inspect 的行为会发生变化。但是当我继承一个自定义的子类时没有看到。
class MainError
end
class AnotherTestError < StandardError
def initialize
@label_test = "hey!"
end
end
class TestError < MainError
def initialize
@label_test = "hey!"
end
end
a = AnotherTestError.new
puts a.inspect # output: #<AnotherTestError: AnotherTestError>
t = TestError.new
puts t.inspect # output: #<TestError:0x007f99e12409f0 @label_test="hey!">
【问题讨论】:
-
非常好的问题! +1
标签: ruby inheritance subclass