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.



22
23
24
# File 'lib/puppet/util/multi_match.rb', line 22

def initialize(*values)
  @values = values
end

Instance Attribute Details

#valuesObject (readonly)

Returns the value of attribute values.



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

def values
  @values
end

Instance Method Details

#===(other) ⇒ Object



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

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