A very simple restructuring of your code could be with one line in your def function -
return "#{m/60}:#{m%60 == 0 ? '00' : m%60}"
Running an example from irb -
2.1.5 :077 > m=100
=> 100
2.1.5 :078 > puts "#{m/60}:#{m%60 == 0 ? '00' : m%60}"
1:40
=> nil
2.1.5 :079 > m=120
=> 120
2.1.5 :080 > puts "#{m/60}:#{m%60 == 0 ? '00' : m%60}"
2:00
=> nil
2.1.5 :081 >
source
share