Class: Klee::Patterns
- Inherits:
-
Object
- Object
- Klee::Patterns
- Includes:
- Enumerable
- Defined in:
- lib/klee/patterns.rb
Instance Method Summary collapse
- #each(&block) ⇒ Object
- #infixes ⇒ Object
-
#initialize(&block) ⇒ Patterns
constructor
A new instance of Patterns.
- #key_for(pattern) ⇒ Object
- #keys ⇒ Object
- #match(which) ⇒ Object
- #prefix(which) ⇒ Object (also: #suffix, #infix)
- #prefixes ⇒ Object
- #suffixes ⇒ Object
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 |
#infixes ⇒ Object
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 |
#keys ⇒ Object
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 |
#prefixes ⇒ Object
22 23 24 |
# File 'lib/klee/patterns.rb', line 22 def prefixes @patterns[:prefix] end |
#suffixes ⇒ Object
30 31 32 |
# File 'lib/klee/patterns.rb', line 30 def suffixes @patterns[:suffix] end |