Name: Anonymous 2012-08-04 2:56
please give me some help
i want to make this as meta/prog/ed as fuck
i want to make this as meta/prog/ed as fuck
class Fixnum
def seconds; self; end
def minutes; seconds.send(:*,60); end
def hours; minutes.send(:*,60); end
def days; hours.send(:*,24); end
def years; days.send(:*,365); end
def ago; Time.now - self; end
def from_now; Time.now + self; end
def to_minutes; self / 60; end
def to_hours; to_minutes / 60; end
def to_days; to_hours / 24; end
def to_years; to_days / 365; end
def method_missing(method_id, *args)
apply_calc = lambda do |op,unit|
unit.send(op)
end
name = method_id.to_s
if name =~ /^(second|minute|hour|day|year)$/
apply_calc.(:*, name + 's')
self.send(name + 's')
else super
end
end
end
def days_old mybd = Time.new("1947-02-23 13:00:00 -0400")
(Time.now - mybd).round.to_hours
end
delta = (1.minute.from_now - Time.now).round.to_hours
#to_hours shouldn't even be explicit it should be metaprogrammed with a new operator