module Rule
  class Product
    DEFAULT_RULE = {product_code:"FR1", qty:2, price:3.11}
    def initialize(rule={})
      @rule = DEFAULT_RULE.merge(rule)
    end

    def apply(checkout)
      ft_products = checkout.cart.select(&:product_code).select{|p| p.product_code == @rule.fetch(:product_code)}
      free_products = ft_products.each_slice(2).select{|p| p.size == 2}.count
      @rule.fetch(:price) * free_products
    end
  end
end
module Rule
  class Product
    DEFAULT_RULE = {product_code:"FR1", qty:2, price:3.11}
    def initialize(rule={})
      @rule = DEFAULT_RULE.merge(rule)
    end

    def apply(checkout)
      ft_products = checkout.cart.select(&:product_code).select{|p| p.product_code == @rule.fetch(:product_code)}
      free_products = ft_products.each_slice(@rule.fetch(:qty)).select{|p| p.size == 2}.count
      @rule.fetch(:price) * free_products
    end
  end
end
Make slice each value configurable to accommodate 3 for 1
Make slice each value configurable to accommodate 3 for 1