lib/ayadn/extend.rb in ayadn-2.1 vs lib/ayadn/extend.rb in ayadn-3.0

- old
+ new

@@ -20,5 +20,25 @@ 'GB' => 1024 * 1024 * 1024 * 1024, 'TB' => 1024 * 1024 * 1024 * 1024 * 1024 }.each_pair { |e, s| return "#{(self.to_f / (s / 1024)).round(2)} #{e}" if self < s } end end +class Object + def blank? + respond_to?(:empty?) ? !!empty? : !self + end +end +class Hash + def deep_diff(b) + a = self + (a.keys | b.keys).inject({}) do |diff, k| + if a[k] != b[k] + if a[k].respond_to?(:deep_diff) && b[k].respond_to?(:deep_diff) + diff[k] = a[k].deep_diff(b[k]) + else + diff[k] = [a[k], b[k]] + end + end + diff + end + end +end \ No newline at end of file