Class: Janeway::AST::UnaryOperator

Inherits:
Expression show all
Defined in:
lib/janeway/ast/unary_operator.rb

Overview

Represent unary operators “!”, “-”

Instance Attribute Summary collapse

Attributes inherited from Expression

#next, #value

Instance Method Summary collapse

Methods inherited from Expression

#indented, #literal?, #singular_query?, #type

Constructor Details

#initialize(operator, operand = nil) ⇒ UnaryOperator

Returns a new instance of UnaryOperator.



9
10
11
12
13
# File 'lib/janeway/ast/unary_operator.rb', line 9

def initialize(operator, operand = nil)
  super()
  @name = operator # eg. :not
  @operand = operand
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



7
8
9
# File 'lib/janeway/ast/unary_operator.rb', line 7

def name
  @name
end

#operandObject

Returns the value of attribute operand.



7
8
9
# File 'lib/janeway/ast/unary_operator.rb', line 7

def operand
  @operand
end

Instance Method Details

#to_sObject



15
16
17
# File 'lib/janeway/ast/unary_operator.rb', line 15

def to_s
  "#{@operator} #{operand}"
end

#tree(level) ⇒ Array

Parameters:

  • level (Integer)

Returns:

  • (Array)


21
22
23
# File 'lib/janeway/ast/unary_operator.rb', line 21

def tree(level)
  indented(level, "#{operator}#{operand}")
end