Created
March 15, 2014 23:56
-
-
Save gevans/9575816 to your computer and use it in GitHub Desktop.
Extension to Ruby's Numeric for easy conversion between hash rate units (adapted from https://github.com/rails/rails/blob/master/activesupport/lib/active_support/core_ext/numeric/bytes.rb).
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
## | |
# Example: | |
# | |
# 123.kilohashes + 1.hash * 1.megahash | |
# => 1123000 | |
# | |
class Numeric | |
KILOHASH = 1000 | |
MEGAHASH = KILOHASH * 1000 | |
GIGAHASH = MEGAHASH * 1000 | |
TERAHASH = GIGAHASH * 1000 | |
PETAHASH = TERAHASH * 1000 | |
EXAHASH = PETAHASH * 1000 | |
def hashes | |
self | |
end | |
alias hash hashes | |
def kilohashes | |
self * KILOHASH | |
end | |
alias kilohash kilohashes | |
def megahashes | |
self * MEGAHASH | |
end | |
alias megahash megahashes | |
def gigahashes | |
self * GIGAHASH | |
end | |
alias gigahash gigahashes | |
def terahashes | |
self * TERAHASH | |
end | |
alias terahash terahashes | |
def petahashes | |
self * PETAHASH | |
end | |
alias petahash petahashes | |
def exahashes | |
self * EXAHASH | |
end | |
alias exahash exahashes | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Scratch that. Overriding
Object#hash
is a really bad idea.