# File lib/algebrick/matchers/array.rb, line 18 def self.call(*matchers) new *matchers end
# File lib/algebrick/matchers/array.rb, line 24 def initialize(*matchers) super() @matchers = matchers raise ArgumentError, 'many can be only last' if @matchers[0..-2].any? { |v| v.is_a?(Many) } end
# File lib/algebrick/matchers/array.rb, line 38 def ==(other) other.kind_of? self.class and self.matchers == other.matchers end
# File lib/algebrick/matchers/array.rb, line 30 def children find_children @matchers end
# File lib/algebrick/matchers/array.rb, line 43 def rest? matchers.last.is_a?(Many) end
# File lib/algebrick/matchers/array.rb, line 34 def to_s "#{assign_to_s}#{"Array.(#{matchers.join(',')})" if matchers}" end
# File lib/algebrick/matchers/array.rb, line 49 def matching?(other) return false unless other.kind_of? ::Array if rest? matchers[0..-2].zip(other).all? { |m, v| m === v } and matchers.last === other[(matchers.size-1)..-1] else matchers.size == other.size and matchers.zip(other).all? { |m, v| m === v } end end