All it does* is return the number of seconds in a day, multiplied by self:
class Fixnum
def day
self * (60 * 60 * 24) # seconds * minutes * hours
end
end
# 10.days => 'self' is 10, so 10 * 60 * 60 * 24
Then, .ago
subtracts that many seconds from Time.now
:
class Fixnum
def ago
Time.now - self
end
end
# 10.days.ago == Time.now - (10 * 60 * 60 * 24)
*This is actually not all it does; in reality it returns a proxy object which represents the given duration. The math is also significantly more complex