Implementation of seconds/minutes/hours, which are rails methods. Note that implicit returns aren't needed, but they look cleaner, so I prefer them. I'm not sure Rails even has .days or if it goes further, but these are the ones I need.
class Integer
def seconds
return self
end
def minutes
return self * 60
end
def hours
return self * 3600
end
def days
return self * 86400
end
end
After this, you can do:
sleep 5.seconds
to sleep for 5 seconds. You can do sleep 5.minutes
to sleep for 5 min. You can do sleep 5.hours
to sleep for 5 hours. And finally, you can do sleep 5.days
to sleep for 5 days... You can add any method that return the value of self * (amount of seconds in that timeframe).
As an exercise, try implementing it for months!