Class: Code::Object::Decimal

Inherits:
Code::Object show all
Defined in:
lib/code/object/decimal.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Code::Object

#fetch

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

#rawObject (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

#hashObject



26
27
28
# File 'lib/code/object/decimal.rb', line 26

def hash
  [self.class, raw].hash
end

#inspectObject



17
18
19
# File 'lib/code/object/decimal.rb', line 17

def inspect
  to_s
end

#to_sObject



13
14
15
# File 'lib/code/object/decimal.rb', line 13

def to_s
  raw.to_s("F")
end