Created
May 15, 2011 21:38
-
-
Save vladimir-vg/973566 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1.year + 2.months + 3.weeks # => 1 year, 2 months, and 21 days | |
2.hours + 30.minutes # => 9000 seconds |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$> 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)> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def weeks | |
ActiveSupport::Duration.new(self * 7.days, [[:days, self * 7]]) | |
end | |
alias :week :weeks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>> Numeric.subclasses | |
=> [Float, Integer, BigDecimal, Date::Infinity, Rational] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>> 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?"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>> 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