lib/erlectricity/matcher.rb in erlectricity-0.2.1 vs lib/erlectricity/matcher.rb in erlectricity-1.0.0

- old
+ new

@@ -1,38 +1,21 @@ module Erlectricity -class Matcher - attr_accessor :condition, :block - attr_accessor :receiver - - def initialize(parent, condition, block) - self.receiver = parent - @block = block - @condition = condition - end - - def run(arg) - args = get_bound arg - block.call *args - end - - def matches?(arg) - if @condition.is_a?(Array) - return false unless arg.is_a?(Array) - return false if @condition.length != arg.length - @condition.zip(arg).all?{|l,r| l.satisfies?(r)} - else - @condition.satisfies?(arg) + class Matcher + attr_accessor :condition, :block + attr_accessor :receiver + + def initialize(parent, condition, block) + self.receiver = parent + @block = block + @condition = Condition.for(condition) end - end - - private - - def get_bound(arg) - if @condition.is_a?(Array) && arg.is_a?(Array) - @condition.zip(arg).map{|l,r| l.binding_for r}.compact - else - @condition.binding_for(arg) + def run(arg) + args = @condition.binding_for(arg) + block.call(*args) end + + def matches?(arg) + @condition.satisfies?(arg) + end end end -end \ No newline at end of file