Class: Puppet::Util::MultiMatch

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet/util/multi_match.rb

Defined Under Namespace

Classes: MatchNotNil

Constant Summary collapse

NOT_NIL =
MatchNotNil.new().freeze
TUPLE =
MultiMatch.new(NOT_NIL, NOT_NIL).freeze
TRIPLE =
MultiMatch.new(NOT_NIL, NOT_NIL, NOT_NIL).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*values) ⇒ MultiMatch

Returns a new instance of MultiMatch.



20
21
22
# File 'lib/puppet/util/multi_match.rb', line 20

def initialize(*values)
  @values = values
end

Instance Attribute Details

#valuesObject (readonly)

Returns the value of attribute values.



18
19
20
# File 'lib/puppet/util/multi_match.rb', line 18

def values
  @values
end

Instance Method Details

#===(other) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/puppet/util/multi_match.rb', line 24

def ===(other)
  lv = @values  # local var is faster than instance var
  case other
  when MultiMatch
    return false unless other.values.size == values.size
    other.values.each_with_index {|v, i| return false unless lv[i] === v || v === lv[i]}
  when Array
    return false unless other.size == values.size
    other.each_with_index {|v, i| return false unless lv[i] === v || v === lv[i]}
  else
    false
  end
  true
end