class Yadriggy::Unary

Unary expression. The splat operator `*` is also a unary operator.

Attributes

op[R]

Returns the operator name. @return [Symbol] the operator name.

If this is a unary plus/minus expression, `:+@` or `:-@` is
returned.
operand[R]

@return [ASTnode] the operand.

Public Class Methods

new(sexp) click to toggle source
# File lib/yadriggy/ast.rb, line 615
def initialize(sexp)
  @op = sexp[1]
  @operand = to_node(sexp[2])
  add_child(@operand)
end
tag() click to toggle source
# File lib/yadriggy/ast.rb, line 613
def self.tag() :unary end

Public Instance Methods

accept(evaluator) click to toggle source

A method for Visitor pattern. @param [Eval] evaluator the visitor of Visitor pattern. @return [void]

# File lib/yadriggy/ast.rb, line 640
def accept(evaluator)
  evaluator.unary(self)
end
const_value() click to toggle source
# File lib/yadriggy/ast_value.rb, line 336
def const_value()
  send_op_to_value(@operand.const_value)
end
const_value_in_class(klass) click to toggle source
# 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() click to toggle source

Returns the real operator name. @return [Symbol] the real operator name.

If the operator is a unary plus or minus, the method returns
`:+` or `:-` although {#op} returns `:+@` or `:-@`.
# File lib/yadriggy/ast.rb, line 626
def real_operator
  case @op
  when :+@
    :+
  when :-@
    :-
  else
    @op
  end
end
value() click to toggle source
# File lib/yadriggy/ast_value.rb, line 328
def value()
  send_op_to_value(@operand.value)
end
value_in_class(klass) click to toggle source
# File lib/yadriggy/ast_value.rb, line 332
def value_in_class(klass)
  send_op_to_value(@operand.value_in_class(klass))
end

Private Instance Methods

send_op_to_value(v) click to toggle source
# File lib/yadriggy/ast_value.rb, line 345
def send_op_to_value(v)
  if v == Undef || is_proc?(v) || !v.class.public_method_defined?(@op)
    Undef
  else
    v.send(@op)
  end
end