Extend the Fixnum class with some helper methods to make manipulating dates easier : Fixnum class « Number « Ruby






Extend the Fixnum class with some helper methods to make manipulating dates easier


class Fixnum
  def seconds
    self
  end
  def minutes
    self * 60
  end
  def hours
    self * 60 * 60
  end
  def days
    self * 60 * 60 * 24
  end
end

puts Time.now
puts Time.now + 10.minutes
puts Time.now + 16.hours
puts Time.now - 7.days

 








Related examples in the same category

1.Fixnum literal value
2.Normal-looking math equations when you use operator methods, such as +
3.Output the modules where Fixnum lives
4.find out the ancestors of Fixnum
5.Raise ArgumentError from method