Class: Klee::Patterns

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/klee/patterns.rb

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Patterns

Returns a new instance of Patterns.



5
6
7
8
# File 'lib/klee/patterns.rb', line 5

def initialize(&block)
  @patterns = Hash.new { |h, k| h[k] = Set.new }
  instance_eval(&block) if block
end

Instance Method Details

#each(&block) ⇒ Object



34
35
36
# File 'lib/klee/patterns.rb', line 34

def each(&block)
  @patterns[:match].each(&block)
end

#infixesObject



26
27
28
# File 'lib/klee/patterns.rb', line 26

def infixes
  @patterns[:infix]
end

#key_for(pattern) ⇒ Object



42
43
44
# File 'lib/klee/patterns.rb', line 42

def key_for(pattern)
  keys.find { pattern =~ _1 }
end

#keysObject



38
39
40
# File 'lib/klee/patterns.rb', line 38

def keys
  @patterns.except(:match).values.inject(Set.new, :+)
end

#match(which) ⇒ Object



17
18
19
20
# File 'lib/klee/patterns.rb', line 17

def match(which)
  @patterns[:match].add which
  which
end

#prefix(which) ⇒ Object Also known as: suffix, infix



10
11
12
13
# File 'lib/klee/patterns.rb', line 10

def prefix(which)
  @patterns[__callee__].add which
  send("to_#{__callee__}", which).tap { match(_1) }
end

#prefixesObject



22
23
24
# File 'lib/klee/patterns.rb', line 22

def prefixes
  @patterns[:prefix]
end

#suffixesObject



30
31
32
# File 'lib/klee/patterns.rb', line 30

def suffixes
  @patterns[:suffix]
end