Module: Symbolic

Includes:
AST
Included in:
ReDuxml::Evaluator
Defined in:
lib/symbolic_ext/coerced.rb,
lib/symbolic_ext/symbolic.rb,
lib/symbolic_ext/variable.rb

Defined Under Namespace

Classes: Coerced, Variable

Instance Method Summary collapse

Methods included from AST

#new_ast

Instance Method Details

#%(var) ⇒ Object



7
8
9
10
11
# File 'lib/symbolic_ext/symbolic.rb', line 7

def %(var)
  return 0 if self.object_id == var.object_id
  return self % var if self.is_a?(Numeric) && var.is_a?(Numeric)
  new_ast :%, var
end

#-@(var) ⇒ Object



13
14
15
16
17
18
# File 'lib/symbolic_ext/symbolic.rb', line 13

def -@(var)
  return -var unless var.is_a?(Node)
  return -var.type if var.type.is_a?(Numeric)
  reversed = var.type.reverse
  reversed ? new_ast(reversed, *var.children.dup) : new_ast(:-@, [var])
end

#not(var) ⇒ Object



20
21
22
23
24
25
# File 'lib/symbolic_ext/symbolic.rb', line 20

def not(var)
  return nil if var.is_a?(Symbolic::Variable)
  return !var unless var.is_a?(Node)
  inverted = var.type.inverse
  inverted ? new_ast(inverted, *var.children.dup) : new_ast(:!, [var])
end