Class: Code::Object::Decimal
- Inherits:
-
Code::Object
- Object
- Code::Object
- Code::Object::Decimal
- Defined in:
- lib/code/object/decimal.rb
Instance Attribute Summary collapse
-
#raw ⇒ Object
readonly
Returns the value of attribute raw.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #hash ⇒ Object
-
#initialize(decimal, exponent: nil) ⇒ Decimal
constructor
A new instance of Decimal.
- #inspect ⇒ Object
- #to_s ⇒ Object
Methods inherited from Code::Object
Constructor Details
#initialize(decimal, exponent: nil) ⇒ Decimal
Returns a new instance of Decimal.
8 9 10 11 |
# File 'lib/code/object/decimal.rb', line 8 def initialize(decimal, exponent: nil) @raw = BigDecimal(decimal) @raw = @raw * 10**exponent.raw if exponent end |
Instance Attribute Details
#raw ⇒ Object (readonly)
Returns the value of attribute raw.
6 7 8 |
# File 'lib/code/object/decimal.rb', line 6 def raw @raw end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
21 22 23 |
# File 'lib/code/object/decimal.rb', line 21 def ==(other) raw == other.raw end |
#hash ⇒ Object
26 27 28 |
# File 'lib/code/object/decimal.rb', line 26 def hash [self.class, raw].hash end |
#inspect ⇒ Object
17 18 19 |
# File 'lib/code/object/decimal.rb', line 17 def inspect to_s end |
#to_s ⇒ Object
13 14 15 |
# File 'lib/code/object/decimal.rb', line 13 def to_s raw.to_s("F") end |