Class: Bankroll::Decimal
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Bankroll::Decimal
- Defined in:
- lib/bankroll/decimal.rb
Constant Summary collapse
- ROUNDING =
:half_even
Instance Attribute Summary collapse
-
#value ⇒ Object
(also: #__getobj__)
readonly
Returns the value of attribute value.
Class Method Summary collapse
Instance Method Summary collapse
- #*(other) ⇒ Object
- #**(other) ⇒ Object
- #+(other) ⇒ Object
- #-(other) ⇒ Object
- #/(other) ⇒ Object
-
#initialize(value) ⇒ Decimal
constructor
A new instance of Decimal.
- #round(precision = 2, rounding = ROUNDING) ⇒ Object
Constructor Details
Instance Attribute Details
#value ⇒ Object (readonly) Also known as: __getobj__
Returns the value of attribute value.
17 18 19 |
# File 'lib/bankroll/decimal.rb', line 17 def value @value end |
Class Method Details
.[](value) ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/bankroll/decimal.rb', line 9 def self.[](value) if value.is_a? self value else new(value.to_s) end end |
Instance Method Details
#*(other) ⇒ Object
45 46 47 |
# File 'lib/bankroll/decimal.rb', line 45 def *(other) wrap super(Decimal[other].value) end |
#**(other) ⇒ Object
53 54 55 |
# File 'lib/bankroll/decimal.rb', line 53 def **(other) wrap super(Decimal[other].value) end |
#+(other) ⇒ Object
37 38 39 |
# File 'lib/bankroll/decimal.rb', line 37 def +(other) wrap super(Decimal[other].value) end |
#-(other) ⇒ Object
41 42 43 |
# File 'lib/bankroll/decimal.rb', line 41 def -(other) wrap super(Decimal[other].value) end |
#/(other) ⇒ Object
49 50 51 |
# File 'lib/bankroll/decimal.rb', line 49 def /(other) wrap super(Decimal[other].value) end |
#round(precision = 2, rounding = ROUNDING) ⇒ Object
33 34 35 |
# File 'lib/bankroll/decimal.rb', line 33 def round(precision = 2, rounding = ROUNDING) wrap @value.round(precision, rounding) end |