Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Hash
- def +(other)
- (self.keys + other.keys).uniq.each do |key|
- if [self[key], other[key]].all?
- if self[key].is_a?(Hash)
- self[key] += other[key]
- elsif self[key].respond_to?(:+)
- self[key] += other[key]
- else
- raise "values for #{key} were neither hashes or summable"
- end
- else
- self[key] ||= other[key] # ignore the nil
- end
- end
- self
- end
- end
Add Comment
Please, Sign In to add comment