Class: Puppet::Parser::AST::InOperator

Inherits:
Branch show all
Defined in:
lib/puppet/parser/ast/in_operator.rb

Instance Attribute Summary collapse

Attributes inherited from Branch

#children, #pin

Instance Method Summary collapse

Methods inherited from Branch

#each, #initialize

Constructor Details

This class inherits a constructor from Puppet::Parser::AST::Branch

Instance Attribute Details

#lvalObject



7
8
9
# File 'lib/puppet/parser/ast/in_operator.rb', line 7

def lval
  @lval
end

#rvalObject



7
8
9
# File 'lib/puppet/parser/ast/in_operator.rb', line 7

def rval
  @rval
end

Instance Method Details

#evaluate(scope) ⇒ Object

Returns a boolean which is the result of the ‘in’ operation of lval and rval operands

Raises:

  • (ArgumentError)


11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/puppet/parser/ast/in_operator.rb', line 11

def evaluate(scope)

  # evaluate the operands, should return a boolean value
  lval = @lval.safeevaluate(scope)
  raise ArgumentError, "'#{lval}' from left operand of 'in' expression is not a string" unless lval.is_a?(::String)

  rval = @rval.safeevaluate(scope)
  unless rval.respond_to?(:include?)
    raise ArgumentError, "'#{rval}' from right operand of 'in' expression is not of a supported type (string, array or hash)"
  end
  rval.include?(lval)
end