Class: Code::Node::Base10

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

Instance Method Summary collapse

Methods inherited from Code::Node

#resolve

Constructor Details

#initialize(parsed) ⇒ Base10

Returns a new instance of Base10.



6
7
8
9
10
11
12
13
14
15
# File 'lib/code/node/base_10.rb', line 6

def initialize(parsed)
  @whole = parsed.delete(:whole)

  @exponent =
    Node::Statement.new(parsed.delete(:exponent)) if parsed.key?(
    :exponent
  )

  super(parsed)
end

Instance Method Details

#evaluate(**args) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/code/node/base_10.rb', line 17

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

    if exponent.is_a?(::Code::Object::Integer)
      ::Code::Object::Integer.new(@whole.to_i, exponent:)
    else
      ::Code::Object::Decimal.new(@whole, exponent:)
    end
  else
    ::Code::Object::Integer.new(@whole.to_i)
  end
end