def binary_search(time, from = 0, to = nil, &block)
      to = private_rules.length - 1 if to.nil?

      return from if from == to

      mid = (from + to).div(2)

      unless yield(time, private_rules[mid])
        return binary_search(time, mid + 1, to, &block)
      end

      return mid if mid.zero?

      return mid unless yield(time, private_rules[mid - 1])

      binary_search(time, from, mid - 1, &block)
    end
def binary_search(time, from = 0, to = nil, &block)
      to = private_rules.length - 1 if to.nil?

      return from if from == to

      mid = (from + to).div(2)

      unless yield(time, private_rules[mid])
        return binary_search(time, mid + 1, to, &block)
      end

      return mid if mid.zero?

      return mid unless yield(time, private_rules[mid - 1])

      binary_search(time, from, mid - 1, &block)
    end
Find the first rule that matches using binary search.