input = 4000 #input in seconds
h = {(60..3599) => ["input/60",'Minutes'], (0..59) => ["input",'Seconds'],(3600..Float::INFINITY) => ["input/3600",'Hours']}
h.each_pair {|k,v| p "#{v.last} is #{eval(v.first)}" if k.include? input}
input = 1100 #input in seconds
h = {(60..3599) => ["input/60",'Minutes'], (0..59) => ["input",'Seconds'],(3600..Float::INFINITY) => ["input/3600",'Hours']}
h.each_pair {|k,v| p "#{v.last} is #{eval(v.first)}" if k.include? input}
input = 14 #input in seconds
h = {(60..3599) => ["input/60",'Minutes'], (0..59) => ["input",'Seconds'],(3600..Float::INFINITY) => ["input/3600",'Hours']}
h.each_pair {|k,v| p "#{v.last} is #{eval(v.first)}" if k.include? input}
输出:
"Hours is 1"
"Minutes is 18"
"Seconds is 14"