Class: Keisan::AST::UnaryOperator

Inherits:
Operator show all
Defined in:
lib/keisan/ast/unary_operator.rb

Constant Summary

Constants inherited from Operator

Operator::ARITIES, Operator::ARITY_PRIORITY_ASSOCIATIVITY, Operator::ASSOCIATIVITIES, Operator::ASSOCIATIVITY_OF_PRIORITY, Operator::PRIORITIES

Instance Attribute Summary

Attributes inherited from Parent

#children

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Operator

#arity, #associativity, associativity_of_priority, #blank_value, #evaluate_assignments, #priority, symbol, #symbol, #value

Methods inherited from Parent

#==, #deep_dup, #evaluate, #freeze, #replace, #unbound_functions, #unbound_variables

Methods inherited from Node

#!, #%, #&, #*, #**, #+, #+@, #-, #-@, #/, #<, #<=, #>, #>=, #^, #and, #coerce, #deep_dup, #differentiate, #equal, #evaluate, #evaluate_assignments, #evaluated, #false?, #not_equal, #or, #replace, #simplified, #to_cell, #to_node, #true?, #unbound_functions, #unbound_variables, #value, #well_defined?, #|, #~

Constructor Details

#initialize(children = []) ⇒ UnaryOperator

Returns a new instance of UnaryOperator.



4
5
6
7
8
9
10
# File 'lib/keisan/ast/unary_operator.rb', line 4

def initialize(children = [])
  children = Array.wrap(children)
  super(children)
  if children.count != 1
    raise Exceptions::ASTError.new("Unary operator takes has a single child")
  end
end

Class Method Details

.arityObject



16
17
18
# File 'lib/keisan/ast/unary_operator.rb', line 16

def self.arity
  ARITIES[:"u#{symbol}"]
end

.associativityObject



24
25
26
# File 'lib/keisan/ast/unary_operator.rb', line 24

def self.associativity
  ASSOCIATIVITIES[:"u#{symbol}"]
end

.priorityObject



20
21
22
# File 'lib/keisan/ast/unary_operator.rb', line 20

def self.priority
  PRIORITIES[:"u#{symbol}"]
end

Instance Method Details

#childObject



12
13
14
# File 'lib/keisan/ast/unary_operator.rb', line 12

def child
  children.first
end

#simplify(context = nil) ⇒ Object



36
37
38
# File 'lib/keisan/ast/unary_operator.rb', line 36

def simplify(context = nil)
  self
end

#to_sObject



28
29
30
31
32
33
34
# File 'lib/keisan/ast/unary_operator.rb', line 28

def to_s
  if child.is_a?(Operator)
    "#{symbol.to_s}(#{child.to_s})"
  else
    "#{symbol.to_s}#{child.to_s}"
  end
end