Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#2800 state:committed] Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
- Loading branch information
Showing
1 changed file
with
15 additions
and
8 deletions.
There are no files selected for viewing
23 changes: 15 additions & 8 deletions
23
activesupport/lib/active_support/core_ext/numeric/bytes.rb
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,44 @@ | ||
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 | ||
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 |