diff options
author | Luca Guidi <guidi.luca@gmail.com> | 2009-06-13 12:43:07 +0200 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2009-06-13 14:03:45 -0700 |
commit | 9eeb5fed2ff8e781e56202f62b125bfadc486999 (patch) | |
tree | 3521370a95acde561ef80b2a5fe0df9fe99dfc13 /activesupport/lib/active_support/core_ext/numeric | |
parent | d32965399ccfa2052a4d52b70db1bae0ca16830b (diff) | |
download | rails-9eeb5fed2ff8e781e56202f62b125bfadc486999.tar.gz rails-9eeb5fed2ff8e781e56202f62b125bfadc486999.tar.bz2 rails-9eeb5fed2ff8e781e56202f62b125bfadc486999.zip |
Bytes calculation speed up
[#2800 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
Diffstat (limited to 'activesupport/lib/active_support/core_ext/numeric')
-rw-r--r-- | activesupport/lib/active_support/core_ext/numeric/bytes.rb | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/activesupport/lib/active_support/core_ext/numeric/bytes.rb b/activesupport/lib/active_support/core_ext/numeric/bytes.rb index 507d651261..deea8e9358 100644 --- a/activesupport/lib/active_support/core_ext/numeric/bytes.rb +++ b/activesupport/lib/active_support/core_ext/numeric/bytes.rb @@ -1,4 +1,11 @@ class Numeric + KILOBYTE = 1024 + MEGABYTE = KILOBYTE * 1024 + GIGABYTE = MEGABYTE * 1024 + TERABYTE = GIGABYTE * 1024 + PETABYTE = TERABYTE * 1024 + EXABYTE = PETABYTE * 1024 + # Enables the use of byte calculations and declarations, like 45.bytes + 2.6.megabytes def bytes self @@ -6,32 +13,32 @@ class Numeric alias :byte :bytes def kilobytes - self * 1024 + self * KILOBYTE end alias :kilobyte :kilobytes def megabytes - self * 1024.kilobytes + self * MEGABYTE end alias :megabyte :megabytes def gigabytes - self * 1024.megabytes + self * GIGABYTE end alias :gigabyte :gigabytes def terabytes - self * 1024.gigabytes + self * TERABYTE end alias :terabyte :terabytes - + def petabytes - self * 1024.terabytes + self * PETABYTE end alias :petabyte :petabytes - + def exabytes - self * 1024.petabytes + self * EXABYTE end alias :exabyte :exabytes end |