Skip to content

Instantly share code, notes, and snippets.

@ljsc
Created August 28, 2008 20:03
Show Gist options
  • Save ljsc/7810 to your computer and use it in GitHub Desktop.
Save ljsc/7810 to your computer and use it in GitHub Desktop.
module TimeMethods
def self.define_time(sym, secs)
module_eval <<-EOC, __FILE__, __LINE__
def #{sym}; self * #{secs} end
alias_method :#{sym}s, :#{sym}
EOC
end
Numeric.send(:include, self)
define_time :second, 1
define_time :minute, 60.seconds
define_time :hour, 60.minutes
define_time :day, 24.hours
define_time :week, 7.days
define_time :year, 364.25.days
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment