Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Bytes calculation speed up

[#2800 state:committed]

Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
  • Loading branch information...
commit 447d60e9ed015e5d6bd336323881f8180c2070d0 1 parent cb9429a
Luca Guidi authored jeremy committed
Showing with 15 additions and 9 deletions.
  1. +15 −9 activesupport/lib/active_support/core_ext/numeric/bytes.rb
View
24 activesupport/lib/active_support/core_ext/numeric/bytes.rb
@@ -3,41 +3,47 @@ module CoreExtensions #:nodoc:
module Numeric #:nodoc:
# Enables the use of byte calculations and declarations, like 45.bytes + 2.6.megabytes
module Bytes
+ KILOBYTE = 1024
+ MEGABYTE = KILOBYTE * 1024
+ GIGABYTE = MEGABYTE * 1024
+ TERABYTE = GIGABYTE * 1024
+ PETABYTE = TERABYTE * 1024
+ EXABYTE = PETABYTE * 1024
+
def bytes
self
end
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
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.