Class: Code::Node::Base10Decimal

Inherits:
Object
  • Object
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(context) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/code/node/base_10_decimal.rb', line 14

def evaluate(context)
  @exponent = @exponent.evaluate(context) if @exponent
  ::Code::Object::Decimal.new(
    "#{sign}#{whole}.#{decimal}",
    exponent: @exponent
  )
end