Class: Code::Node::Base10Decimal

Inherits:
Code::Node show all
Defined in:
lib/code/node/base_10_decimal.rb

Instance Method Summary collapse

Constructor Details

#initialize(number) ⇒ Base10Decimal

Returns a new instance of Base10Decimal.



4
5
6
7
8
9
10
11
12
# File 'lib/code/node/base_10_decimal.rb', line 4

def initialize(number)
  @sign = number[:sign]
  @whole = number.fetch(:whole)
  @decimal = number.fetch(:decimal)

  if number.key?(:exponent)
    @exponent = ::Code::Node::Base10Number.new(number[:exponent])
  end
end

Instance Method Details

#evaluate(**args) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/code/node/base_10_decimal.rb', line 14

def evaluate(**args)
  if @exponent
    exponent = @exponent.evaluate(**args)

    ::Code::Object::Decimal.new(
      "#{sign}#{whole}.#{decimal}",
      exponent: exponent,
    )
  else
    ::Code::Object::Decimal.new("#{sign}#{whole}.#{decimal}")
  end
end