Module: Diamond::Pattern::ClassMethods

Included in:
Diamond::Pattern
Defined in:
lib/diamond/pattern.rb

Instance Method Summary collapse

Instance Method Details

#<<(pattern) ⇒ Array<Pattern>

Add a pattern

Parameters:

Returns:



32
33
34
# File 'lib/diamond/pattern.rb', line 32

def <<(pattern)
  all << pattern
end

#add(*args, &block) ⇒ Array<Pattern>

Construct and add a pattern

Parameters:

  • name (Symbol, String)
  • block (Proc)

Returns:



25
26
27
# File 'lib/diamond/pattern.rb', line 25

def add(*args, &block)
  all << new(*args, &block)
end

#allArray<Pattern>

All patterns

Returns:



10
11
12
# File 'lib/diamond/pattern.rb', line 10

def all
  @patterns ||= []
end

#find(name) ⇒ Pattern

Find a pattern by its name (case insensitive)

Parameters:

  • name (String, Symbol)

Returns:



17
18
19
# File 'lib/diamond/pattern.rb', line 17

def find(name)
  all.find { |pattern| pattern.name.to_s.downcase == name.to_s.downcase }
end

#firstPattern

Returns:



37
38
39
# File 'lib/diamond/pattern.rb', line 37

def first
  all.first
end

#lastPattern

Returns:



42
43
44
# File 'lib/diamond/pattern.rb', line 42

def last
  all.last
end