# Fri Jul 29 14:01:38 MDT 2005 Copylefted David Baird # See also: # ri define_method # http://www.ruby-doc.org/core/classes/Module.html#M000701 # ri Symbol # http://www.rubycentral.com/ref/ref_c_symbol.html class Time def initialize @seconds = 0 end attr_accessor :seconds [ [:seconds, 60.0, :minutes], [:minutes, 60.0, :hours], [:hours, 24.0, :days], [:days, 7.0, :weeks], [:days, 365.25, :years], # ...this is a wee bit off [:weeks, 2.0, :fortnights], [:years, 20.0, :scores], ].each { |from, divide_by, to| define_method(to) { self.send(from) / divide_by } define_method(to.to_s + "=") { |x| self.send(from.to_s + "=", x * divide_by) } } end time = Time.new time.minutes = 3 puts time.seconds puts time.days