The Money gem is a popular gem for Ruby. Ruby needs a gem like Money, for Bitcoin!
But BTC is unique, so this simple object should be unique.
Add this line to your application's Gemfile:
And then execute:
Or install it yourself as:
$ gem install bitcoin-money
Create from whichever unit of BTC.
a = BTC.new(0.012) b = BTC.from_mbtc(12) c = BTC.from_satoshis(120000) a == b # true b == c # true # a == b == c
Get value in any unit of BTC.
b # => #<Btc BTC:0.012 mBTC: 12.0 Satoshis: 120000.0> b.mbtc # => BigDecimal.new('12.0') b.satoshis # => BigDecimal.new('120000.0') b.btc # => BigDecimal.new('0.012')
a + b # == BTC.new(0.024) a * a # == BTC.new(0.000144) a / c # == BTC.new(1) # also ** and -
- Fork it ( https://github.com/zenchilabs/bitcoin-money/fork )
- Create your feature branch (
git checkout -b my-new-feature)
- Commit your changes (
git commit -am 'Add some feature')
- Push to the branch (
git push origin my-new-feature)
- Create a new Pull Request