class A
def initialize(string, number)
@string = string
@number = number
end
def to_s
"In to_s:\n #{@string}, #{@number}\n"
end
def to_a
"In to_a:\n #{@string}, #{@number}\n"
end
end
puts a = A.new("hello world", 5)
出力は
In to_s:
hello world, 5
メソッドはどのようにto_s自動的に呼び出されますか?
などの別のメソッドが自動的に呼び出されないのはなぜto_aですか?
メソッドにputs を書いていないのでto_s、出力が表示されるのはなぜですか。