Class Rinda::Template
In: rinda/rinda.rb
Parent: Tuple

Templates are used to match tuples in Rinda.

Methods

===   match  

Public Instance methods

Alias for match.

[Source]

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

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

[Source]

# 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

[Validate]

ruby-doc.org is hosted and maintained by James Britt and Happy Camper Studios, a Ruby application development company in Phoenix, Arizona. The site was created in 2002 as part of the Ruby Documentation Project to promote the Ruby language and to help other Ruby hackers.

Documentation content on ruby-doc.org is provided by remarkable members of the Ruby community.

For more information on the Ruby programming language, visit ruby-lang.org.

Want to help improve Ruby's API docs? See Ruby Documentation Guidelines.