Class: Hash

Inherits:
Object
  • Object
show all
Defined in:
lib/crunchr/core_ext.rb

Overview

stuff for dealing with statistics

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

Instance Method Summary collapse

Instance Method Details

#delta(other) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# 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