Created
October 20, 2013 15:28
-
-
Save ascendbruce/7071080 to your computer and use it in GitHub Desktop.
ruby 陽春模仿 1.year/month/day, Array#sum
This file contains hidden or 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
| # ruby Fixnum# year/month/day | |
| class Fixnum | |
| def minutes | |
| self*60 | |
| end | |
| def hours | |
| self*60*60 | |
| end | |
| def days | |
| self*24*60*60 | |
| end | |
| end | |
| # Array#sum | |
| # ruby 1.9 above: | |
| array.inject(:+) | |
| # ruby 1.8: | |
| array.inject{|sum,x| sum + x } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment