1
考慮以下幾點:Ruby對象打印格式
irb(main):001:0> class A
irb(main):002:1> def initialize
irb(main):003:2> @string = "my string"
irb(main):004:2> end
irb(main):005:1> def to_s
irb(main):006:2> puts @string
irb(main):007:2> end
irb(main):008:1> end
=> nil
irb(main):009:0> a = A.new
=> #<A:0x2ea606c @string="my string">
irb(main):010:0> puts a
my string
#<A:0x2ea606c>
=> nil
當「放」輸出字符串我是否也追加對象的REFFERENCE?
無論如何擺脫這種行爲?我想outputed是甫一字符串@string作爲階級「to_s」的方法定義
感謝,
RM