class Rinda::Template

Templates are used to match tuples in Rinda.

Public Instance Methods

===(tuple) click to toggle source

Alias for match.

# File lib/rinda/rinda.rb, line 169
def ===(tuple)
match(tuple) click to toggle source

Matches this template against tuple. The tuple must be the same size as the template. An element with a nil value in a template acts as a wildcard, matching any value in the corresponding position in the tuple. Elements of the template match the tuple if the are #== or ===.[:foo, 5]).match[:foo, 5]) # => true[:foo, nil]).match[:foo, 5]) # => true[String]).match['hello']) # => true[:foo]).match[:foo, 5]) # => false[:foo, 6]).match[:foo, 5]) # => false[:foo, nil]).match[:foo])    # => false[:foo, 6]).match[:foo])    # => false
# File lib/rinda/rinda.rb, line 148
def match(tuple)
  return false unless tuple.respond_to?(:size)
  return false unless tuple.respond_to?(:fetch)
  return false unless self.size == tuple.size
  each do |k, v|
      it = tuple.fetch(k)
      return false
    next if v.nil?
    next if v == it
    next if v === it
    return false
  return true