Class: ExaltedMath::Node::Operator

Inherits:
ExaltedMath::Node show all
Defined in:
lib/exalted_math/node/operator.rb

Direct Known Subclasses

Add, Divide, Multiply, Subtract

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(left, right) ⇒ Operator

Returns a new instance of Operator.



8
9
10
11
# File 'lib/exalted_math/node/operator.rb', line 8

def initialize(left, right)
  @left  = left
  @right = right
end

Instance Attribute Details

#leftObject (readonly)

Returns the value of attribute left.



6
7
8
# File 'lib/exalted_math/node/operator.rb', line 6

def left
  @left
end

#rightObject (readonly)

Returns the value of attribute right.



6
7
8
# File 'lib/exalted_math/node/operator.rb', line 6

def right
  @right
end

Instance Method Details

#==(o) ⇒ Object



29
30
31
32
# File 'lib/exalted_math/node/operator.rb', line 29

def ==(o)
  return false unless self.class === o
  left == o.left && right == o.right
end

#constant?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/exalted_math/node/operator.rb', line 13

def constant?
  left.constant? and right.constant?
end

#simplifyObject



21
22
23
24
25
26
27
# File 'lib/exalted_math/node/operator.rb', line 21

def simplify
  if constant?
    Number.new(value)
  else
    self.class.new(left.simplify, right.simplify)
  end
end

#valid?(stats = []) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/exalted_math/node/operator.rb', line 34

def valid?(stats=[])
  left.valid?(stats) && right.valid?(stats)
end

#value(context = {}) ⇒ Object

Raises:

  • (NotImplementedError)


17
18
19
# File 'lib/exalted_math/node/operator.rb', line 17

def value(context={})
  raise NotImplementedError
end