module Speculation::Predicates

Collection of predicate methods used within Speculation. These may appear as the value for the `:pred` key in the return value of `Speculation.explain_data`.

Public Class Methods

array?(x) click to toggle source
# File lib/speculation/predicates.rb, line 10
def self.array?(x)
  x.respond_to?(:at) && x.respond_to?(:[])
end
collection?(xs) click to toggle source
# File lib/speculation/predicates.rb, line 14
def self.collection?(xs)
  xs.respond_to?(:each)
end
count_between?(min_count, max_count, coll) click to toggle source
# File lib/speculation/predicates.rb, line 36
def self.count_between?(min_count, max_count, coll)
  coll.count.between?(min_count, max_count)
end
count_eq?(count, coll) click to toggle source
# File lib/speculation/predicates.rb, line 32
def self.count_eq?(count, coll)
  coll.count == count
end
distinct?(xs) click to toggle source
# File lib/speculation/predicates.rb, line 18
def self.distinct?(xs)
  seen = Set[]

  xs.each do |x|
    if seen.include?(x)
      return false
    else
      seen << x
    end
  end

  true
end
empty?(coll) click to toggle source
# File lib/speculation/predicates.rb, line 44
def self.empty?(coll)
  coll.empty?
end
hash?(x) click to toggle source
# File lib/speculation/predicates.rb, line 6
def self.hash?(x)
  x.respond_to?(:store) && x.respond_to?(:key?) && x.respond_to?(:[])
end
key?(hash, key) click to toggle source
# File lib/speculation/predicates.rb, line 40
def self.key?(hash, key)
  hash.key?(key)
end