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.
594 595 596 597 598 |
# File 'lib/yadriggy/ast.rb', line 594 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.
587 588 589 |
# File 'lib/yadriggy/ast.rb', line 587 def op @op end |
#operand ⇒ ASTnode (readonly)
Returns the operand.
590 591 592 |
# File 'lib/yadriggy/ast.rb', line 590 def operand @operand end |
Class Method Details
.tag ⇒ Object
592 |
# File 'lib/yadriggy/ast.rb', line 592 def self.tag() :unary end |
Instance Method Details
#accept(evaluator) ⇒ void
This method returns an undefined value.
A method for Visitor pattern.
619 620 621 |
# File 'lib/yadriggy/ast.rb', line 619 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.
605 606 607 608 609 610 611 612 613 614 |
# File 'lib/yadriggy/ast.rb', line 605 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 |