Class: Arithmetic::OperandNode

Inherits:
Object
  • Object
show all
Defined in:
lib/arithmetic/nodes.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(operand) ⇒ OperandNode

Returns a new instance of OperandNode.



5
6
7
# File 'lib/arithmetic/nodes.rb', line 5

def initialize(operand)
  @operand = operand
end

Instance Attribute Details

#operandObject

Returns the value of attribute operand.



3
4
5
# File 'lib/arithmetic/nodes.rb', line 3

def operand
  @operand
end

Instance Method Details

#evalObject



13
14
15
16
17
18
19
# File 'lib/arithmetic/nodes.rb', line 13

def eval
  if has_dangling_decimal_point?
    BigDecimal(@operand + "0")
  else
    BigDecimal(@operand)
  end
end

#to_s(visitor, na = nil) ⇒ Object



9
10
11
# File 'lib/arithmetic/nodes.rb', line 9

def to_s(visitor, na=nil)
  visitor.call(@operand)
end