diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2013-10-11 06:06:54 -0700 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2013-10-11 06:06:54 -0700 |
commit | e5f5a838b96a362534d9bb60d02334439ed9784c (patch) | |
tree | 0e13b004047a0c7e24759c507bd23e752a9e2ec6 /guides | |
parent | d7567f3290a50952494e9213556a1f283a6cf3a0 (diff) | |
parent | 90871f7198f0739c82df2f1bbb66c5f8dd5a720a (diff) | |
download | rails-e5f5a838b96a362534d9bb60d02334439ed9784c.tar.gz rails-e5f5a838b96a362534d9bb60d02334439ed9784c.tar.bz2 rails-e5f5a838b96a362534d9bb60d02334439ed9784c.zip |
Merge pull request #12480 from iwiznia/master
flatten and flatten! methods for ActiveSupport::Duration
Diffstat (limited to 'guides')
-rw-r--r-- | guides/source/active_support_core_extensions.md | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/guides/source/active_support_core_extensions.md b/guides/source/active_support_core_extensions.md index d3f49b19fa..d11c17117e 100644 --- a/guides/source/active_support_core_extensions.md +++ b/guides/source/active_support_core_extensions.md @@ -3699,6 +3699,21 @@ Time.utc(1582, 10, 3) + 5.days # => Mon Oct 18 00:00:00 UTC 1582 ``` +When addinng or substracting durations, the resulting duration will be equivalent to subsequent calls to since or advance, so: + +```ruby +Date.new(2013,1,28) + 1.month + 1.month +# => Thu, 28 Mar 2013 +``` + +If you want to add durations and then use them as just one call to since or advance, you can use the flatten or flatten! method: + +```ruby +Date.new(2013,1,31) + (1.month + 1.month).flatten +# => Sun, 31 Mar 2013 +``` + + Extensions to `File` -------------------- |