Skip to content

Instantly share code, notes, and snippets.

@vladimir-vg
Created May 15, 2011 21:38
Show Gist options
  • Save vladimir-vg/973566 to your computer and use it in GitHub Desktop.
Save vladimir-vg/973566 to your computer and use it in GitHub Desktop.
1.year + 2.months + 3.weeks # => 1 year, 2 months, and 21 days
2.hours + 30.minutes # => 9000 seconds
$> rvm use rbx
Using /home/v/.rvm/gems/rbx-head
$> rails c
Loading development environment (Rails 3.0.7)
>> a = 3
=> 3
>> a.method :weeks
=> #<Method: Fixnum#weeks (defined in Numeric at <skipped>/gems/activesupport-3.0.7
/lib/active_support
/core_ext/numeric
/time.rb:52)>
def weeks
ActiveSupport::Duration.new(self * 7.days, [[:days, self * 7]])
end
alias :week :weeks
>> Numeric.subclasses
=> [Float, Integer, BigDecimal, Date::Infinity, Rational]
>> Numeric.instance_methods - Object.instance_methods
=> ["fdiv", "<=>", "zero?", "abs", "ceil", "step", "remainder",
"coerce", "initialize_copy", "truncate", "to_int", "modulo",
"+@", "div", "integer?", "nonzero?", "floor", "redo_compare",
"-@", "divmod", "quo", "round", ">", ">=", "<", "<=", "between?"]
>> a = ActiveSupport::Duration.new 100, [[:seconds, 100]]
=> 100 seconds
>> a.class
=> Fixnum
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment