aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/numeric/bytes.rb
diff options
context:
space:
mode:
authorPratik Naik <pratiknaik@gmail.com>2009-07-03 13:01:39 +0100
committerPratik Naik <pratiknaik@gmail.com>2009-07-03 13:01:39 +0100
commit2fe263bb328c20539f2970057f31e567ec4ab7c8 (patch)
tree63e85164fb09aca6beb78e1a5c52424fa49ed098 /activesupport/lib/active_support/core_ext/numeric/bytes.rb
parentbf5ac9965f12840d469ef2a4a16e8205dbbe5253 (diff)
parenta4bdc00fec623f72592e663e6d7830eea0bc6ea4 (diff)
downloadrails-2fe263bb328c20539f2970057f31e567ec4ab7c8.tar.gz
rails-2fe263bb328c20539f2970057f31e567ec4ab7c8.tar.bz2
rails-2fe263bb328c20539f2970057f31e567ec4ab7c8.zip
Merge commit 'mainstream/master'
Conflicts: actionpack/lib/action_controller.rb actionpack/lib/action_controller/base/base.rb actionpack/lib/action_view/template/path.rb activesupport/lib/active_support/json/encoders/hash.rb
Diffstat (limited to 'activesupport/lib/active_support/core_ext/numeric/bytes.rb')
-rw-r--r--activesupport/lib/active_support/core_ext/numeric/bytes.rb23
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