Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
def sumof s = 12 + 17 puts "The sum of 12 and 17 is: " + s end
sumofを呼び出すと 、エラーが発生します
助けてくれてありがとう
文字列に変換する方法は 1 つだけですが、複数の方法で使用できます。メソッドがto_s(文字列に対して) 呼び出されます。
to_s
方法 1 (手動):
"Some string " + num.to_s
方法 2 (補間):
"Some string #{num}"
あなたはやりたいと思うでしょう
"The sum is " + s.to_sまた"The sum is #{s}"
"The sum is " + s.to_s
"The sum is #{s}"
問題は、元の例では文字列への変換が暗黙的に行われないことです。