Class: Code::Node::Base10
- Inherits:
-
Code::Node
- Object
- Code::Node
- Code::Node::Base10
- Defined in:
- lib/code/node/base_10.rb
Instance Method Summary collapse
- #evaluate(**args) ⇒ Object
-
#initialize(parsed) ⇒ Base10
constructor
A new instance of Base10.
Methods inherited from Code::Node
Constructor Details
#initialize(parsed) ⇒ Base10
Returns a new instance of Base10.
6 7 8 9 10 11 12 13 14 |
# File 'lib/code/node/base_10.rb', line 6 def initialize(parsed) return if parsed.blank? @whole = parsed.delete(:whole).presence return unless parsed.key?(:exponent) @exponent = Node::Statement.new(parsed.delete(:exponent).presence) end |
Instance Method Details
#evaluate(**args) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/code/node/base_10.rb', line 16 def evaluate(**args) if @exponent && @whole exponent = @exponent.evaluate(**args) if exponent.is_a?(Object::Integer) Object::Integer.new(@whole, exponent) else Object::Decimal.new(@whole, exponent) end elsif @whole Object::Integer.new(@whole.to_i) else Object::Nothing.new end end |