Skip to content

Instantly share code, notes, and snippets.

@ridiculous
Last active August 29, 2015 14:11
Show Gist options
  • Save ridiculous/211282a3986255b607da to your computer and use it in GitHub Desktop.
Save ridiculous/211282a3986255b607da to your computer and use it in GitHub Desktop.
Notes + operator
def +(other)
new_data = data.merge(other.data) do |_, val, other_val|
case val
when Array, Integer
val + other_val
when Hash
val.merge(other_val) { |__, val1, val2| val1 + val2 }
else
nil
end
end
self.class.new(new_data)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment