Class: Keisan::AST::UnaryOperator
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, #is_constant?, #replace, #traverse, #unbound_functions, #unbound_variables
Methods inherited from Node
#!, #%, #&, #*, #**, #+, #+@, #-, #-@, #/, #<, #<<, #<=, #>, #>=, #>>, #^, #and, #coerce, #contains_a?, #deep_dup, #differentiate, #differentiated, #equal, #evaluate, #evaluate_assignments, #evaluated, #false?, #is_constant?, #not_equal, #or, #replace, #replaced, #simplified, #to_cell, #to_node, #traverse, #true?, #unbound_functions, #unbound_variables, #value, #well_defined?, #|, #~
Constructor Details
#initialize(children = []) ⇒ UnaryOperator
4
5
6
7
8
9
10
|
# File 'lib/keisan/ast/unary_operator.rb', line 4
def initialize(children = [])
children = Array(children)
super(children)
if children.count != 1
raise Exceptions::ASTError.new("Unary operator takes has a single child")
end
end
|
Class Method Details
.arity ⇒ Object
16
17
18
|
# File 'lib/keisan/ast/unary_operator.rb', line 16
def self.arity
ARITIES[:"u#{symbol}"]
end
|
.associativity ⇒ Object
24
25
26
|
# File 'lib/keisan/ast/unary_operator.rb', line 24
def self.associativity
ASSOCIATIVITIES[:"u#{symbol}"]
end
|
.priority ⇒ Object
20
21
22
|
# File 'lib/keisan/ast/unary_operator.rb', line 20
def self.priority
PRIORITIES[:"u#{symbol}"]
end
|
Instance Method Details
#child ⇒ Object
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_s ⇒ Object
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
|