# File lib/algebrick/matchers/abstract.rb, line 21 def initialize @assign, @value, @matched = nil end
# File lib/algebrick/matchers/abstract.rb, line 52 def ! Not.new self end
# File lib/algebrick/matchers/abstract.rb, line 44 def &(matcher) And.new self, matcher end
# File lib/algebrick/matchers/abstract.rb, line 102 def ==(other) raise NotImplementedError end
# File lib/algebrick/matchers/abstract.rb, line 82 def ===(other) matching?(other).tap { |matched| @value = other if (@matched = matched) } end
# File lib/algebrick/matchers/abstract.rb, line 31 def >(block) return self, block end
# File lib/algebrick/matchers/abstract.rb, line 37 def assign! @assign = true self end
# File lib/algebrick/matchers/abstract.rb, line 56 def assign? @assign end
# File lib/algebrick/matchers/abstract.rb, line 86 def assign_to_s assign? ? '~' : '' end
# File lib/algebrick/matchers/abstract.rb, line 60 def assigned? !!@value end
# File lib/algebrick/matchers/abstract.rb, line 72 def assigns collect_assigns.tap do return yield *assigns if block_given? end end
# File lib/algebrick/matchers/abstract.rb, line 25 def case(&block) return self, block end
# File lib/algebrick/matchers/abstract.rb, line 94 def children raise NotImplementedError end
# File lib/algebrick/matchers/abstract.rb, line 68 def children_including_self children.unshift self end
# File lib/algebrick/matchers/abstract.rb, line 90 def inspect to_s end
# File lib/algebrick/matchers/abstract.rb, line 64 def matched? @matched end
# File lib/algebrick/matchers/abstract.rb, line 78 def to_a assigns end
# File lib/algebrick/matchers/abstract.rb, line 98 def to_s raise NotImplementedError end
# File lib/algebrick/matchers/abstract.rb, line 48 def |(matcher) Or.new self, matcher end
TODO pretty_print for all matchers
# File lib/algebrick/matchers/abstract.rb, line 110 def matching?(other) raise NotImplementedError end
# File lib/algebrick/matchers/abstract.rb, line 116 def collect_assigns mine = @assign ? [@value] : [] children.inject(mine) { |assigns, child| assigns + child.assigns } end
# File lib/algebrick/matchers/abstract.rb, line 126 def find_children(collection) collection.map do |matcher| matcher if matcher.kind_of? Abstract end.compact end
# File lib/algebrick/matchers/abstract.rb, line 121 def matchable!(obj) raise ArgumentError, 'object does not respond to :===' unless obj.respond_to? :=== obj end