プログラミング初心者です。課題の解答例の一部に不明な点があったので質問させていただきます。
課題は、「分表示を何時何分表示への変換」です。課題と解答例の原文がこちらです。
lang
1# Write a method that will take in a number of minutes, and returns a 2# string that formats the number into `hours:minutes`. 3 4 5def time_conversion(minutes) 6 hours = 0 7 8 while minutes >= 60 9 hours += 1 10 minutes -= 60 11 end 12 13 if minutes < 10 14 minutes_s = "0" + minutes.to_s #←このminutes_sとto_s 15 else 16 minutes_s = minutes.to_s #←このminutes_sとto_s 17 end 18 19 return hours.to_s + ":" + minutes_s #←このminutes_sとto_s 20end 21 22# These are tests to check that your code is working. After writing 23# your solution, they should all print true. 24 25puts('time_conversion(15) == "0:15": ' + (time_conversion(15) == '0:15').to_s) 26puts('time_conversion(150) == "2:30": ' + (time_conversion(150) == '2:30').to_s) 27puts('time_conversion(360) == "6:00": ' + (time_conversion(360) == '6:00').to_s)
この解答例の「minutes_s」の「_s」はどのような意味があるのでしょうか?
この「_s」をつけなくても問題なく実行されました。
さらに「minutes.to_s」や「hours.to_s」のto_sメソッドがよくわかりません。というか、to_sメソッドがよくわかりません。一概には言えないと思いますが、わかりやすく教えていただけると幸いです。
ちなみに、このto_sメソッドはつけなければエラーが出ました。
以上の「_s」と「to_s」をご教授お願いします。

回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2015/10/18 07:25
2015/10/18 07:48
2015/10/20 10:22