Class: Yadriggy::Unary
- Includes:
- AstHelper
- Defined in:
- lib/yadriggy/ast.rb,
lib/yadriggy/ast_value.rb
Overview
Unary expression.
The splat operator *
is also a unary operator.
Instance Attribute Summary collapse
-
#op ⇒ Symbol
readonly
Returns the operator name.
-
#operand ⇒ ASTnode
readonly
The operand.
Attributes inherited from ASTnode
Class Method Summary collapse
Instance Method Summary collapse
-
#accept(evaluator) ⇒ void
A method for Visitor pattern.
- #const_value ⇒ Object
- #const_value_in_class(klass) ⇒ Object
-
#initialize(sexp) ⇒ Unary
constructor
A new instance of Unary.
-
#real_operator ⇒ Symbol
Returns the real operator name.
- #value ⇒ Object
- #value_in_class(klass) ⇒ Object
Methods included from AstHelper
#has_tag?, #to_node, #to_nodes
Methods inherited from ASTnode
#add_child, #add_children, #get_context_class, #get_receiver_object, #is_proc?, #pretty_print, #root, #source_location, #source_location_string
Constructor Details
#initialize(sexp) ⇒ Unary
Returns a new instance of Unary.
619 620 621 622 623 |
# File 'lib/yadriggy/ast.rb', line 619 def initialize(sexp) @op = sexp[1] @operand = to_node(sexp[2]) add_child(@operand) end |
Instance Attribute Details
#op ⇒ Symbol (readonly)
Returns the operator name.
612 613 614 |
# File 'lib/yadriggy/ast.rb', line 612 def op @op end |
#operand ⇒ ASTnode (readonly)
Returns the operand.
615 616 617 |
# File 'lib/yadriggy/ast.rb', line 615 def operand @operand end |
Class Method Details
.tag ⇒ Object
617 |
# File 'lib/yadriggy/ast.rb', line 617 def self.tag() :unary end |
Instance Method Details
#accept(evaluator) ⇒ void
This method returns an undefined value.
A method for Visitor pattern.
644 645 646 |
# File 'lib/yadriggy/ast.rb', line 644 def accept(evaluator) evaluator.unary(self) end |
#const_value ⇒ Object
336 337 338 |
# File 'lib/yadriggy/ast_value.rb', line 336 def const_value() send_op_to_value(@operand.const_value) end |
#const_value_in_class(klass) ⇒ Object
340 341 342 |
# File 'lib/yadriggy/ast_value.rb', line 340 def const_value_in_class(klass) send_op_to_value(@operand.const_value_in_class(klass)) end |
#real_operator ⇒ Symbol
Returns the real operator name.
630 631 632 633 634 635 636 637 638 639 |
# File 'lib/yadriggy/ast.rb', line 630 def real_operator case @op when :+@ :+ when :-@ :- else @op end end |
#value ⇒ Object
328 329 330 |
# File 'lib/yadriggy/ast_value.rb', line 328 def value() send_op_to_value(@operand.value) end |
#value_in_class(klass) ⇒ Object
332 333 334 |
# File 'lib/yadriggy/ast_value.rb', line 332 def value_in_class(klass) send_op_to_value(@operand.value_in_class(klass)) end |