class Hash

stuff for dealing with statistics

monkey patches Hash, Array, ActiveRecord::Base and ActiveRecord::Relation

Public Instance Methods

delta(other) click to toggle source
# File lib/crunchr/core_ext.rb, line 7
def delta(other)
  return nil unless other.is_a?(Hash)

  delta = {}

  self.keys.each do |key|
    next if !other.has_key? key
    if self[key].is_a?(Hash)
      delta[key] = self[key].delta(other[key])
    else
      delta[key] = (self[key] - other[key]) rescue nil
    end
  end

  delta
end