Please see the following code (taken from Learning Ruby book):
def timer(start)
puts "Minutes: " + start.to_s
start_time = Time.now
puts start_time.strftime("Start time: %I:%M:%S: %p")
start.downto(1) { |i| sleep 60 }
end_time = Time.now
print end_time.strftime("Elapsed time: %I:%M:%S: %p\n")
end
timer 10
Why would there be a need to change the start variable into a string on the puts line? Couldn't I, for example, simply put in puts "Minutes: #{start}"?
Also, the start.downto(1) line: Is the block {|i| sleep 60} specifying how many seconds a minute should be?
def timer(start). Reply not required, as I'll be deleting this comment.{ |i| sleep 60 }can be written{ sleep 60 }, since the iterator variableiis not used.def timershould bedef timer(start). Please correct that.