Class: Ruby::Rego::AST::UnaryOp

Inherits:
Base
  • Object
show all
Defined in:
lib/ruby/rego/ast/unary_op.rb

Overview

Represents a unary operation (e.g. negation).

Constant Summary collapse

OPERATORS =
%i[not minus].freeze

Instance Attribute Summary collapse

Attributes inherited from Base

#location

Instance Method Summary collapse

Methods inherited from Base

#==, #accept, #deconstruct_keys, #eql?, format_value, #hash, #to_s

Constructor Details

#initialize(operator:, operand:, location: nil) ⇒ UnaryOp

Returns a new instance of UnaryOp.

Parameters:

  • operator (Symbol)
  • operand (Object)
  • location (Location, nil) (defaults to: nil)


15
16
17
18
19
20
# File 'lib/ruby/rego/ast/unary_op.rb', line 15

def initialize(operator:, operand:, location: nil)
  @operator = operator
  validate_operator!
  super(location: location)
  @operand = operand
end

Instance Attribute Details

#operandObject (readonly)

Returns:

  • (Object)


26
27
28
# File 'lib/ruby/rego/ast/unary_op.rb', line 26

def operand
  @operand
end

#operatorSymbol (readonly)

Returns:

  • (Symbol)


23
24
25
# File 'lib/ruby/rego/ast/unary_op.rb', line 23

def operator
  @operator
end