Class: Rinda::Template (Ruby 2.7.5)
Description: Class : Rinda::Template - Ruby 2.7.5

### Home Classes Methods

### In Files

- rinda/rinda.rb

### Parent

Rinda::Tuple

### Methods

- #===
- #match

### Class/Module Index

Quicksearch

- Rinda
- Rinda::DRbObjectTemplate
- Rinda::InvalidHashTupleKey
- Rinda::NotifyTemplateEntry
- Rinda::RequestCanceledError
- Rinda::RequestExpiredError
- Rinda::RindaError
- Rinda::RingFinger
- Rinda::RingProvider
- Rinda::RingServer
- Rinda::SimpleRenewer
- Rinda::Template
- Rinda::TemplateEntry
- Rinda::Tuple
- Rinda::TupleBag
- Rinda::TupleBag::TupleBin
- Rinda::TupleEntry
- Rinda::TupleSpace
- Rinda::TupleSpaceProxy
- Rinda::WaitTemplateEntry

No matching classes.

# Rinda::Template

Templates are used to match tuples in `Rinda`.

### Public Instance Methods

===(tuple) click to toggle source

Alias for `match`.

                   # File rinda/rinda.rb, line 169
    def ===(tuple)
      match(tuple)
    end

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 `===`.

    Template.new([:foo, 5]).match   Tuple.new([:foo, 5]) # => true
    Template.new([:foo, nil]).match Tuple.new([:foo, 5]) # => true
    Template.new([String]).match    Tuple.new(['hello']) # => true

    Template.new([:foo]).match      Tuple.new([:foo, 5]) # => false
    Template.new([:foo, 6]).match   Tuple.new([:foo, 5]) # => false
    Template.new([:foo, nil]).match Tuple.new([:foo])    # => false
    Template.new([:foo, 6]).match   Tuple.new([:foo])    # => false

                   # File 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|
        begin
          it = tuple.fetch(k)
        rescue
          return false
        end
        next if v.nil?
        next if v == it
        next if v === it
        return false
      end
      return true
    end