Module: Tins::HashUnion
- Defined in:
- lib/tins/hash_union.rb
Overview
A module that provides union functionality for hash-like objects
This module implements the | (pipe) operator for hashes, allowing them to be merged with other hash-like objects. The merge gives precedence to values from the other object, making it useful for configuration merging where default values should be overridden by user-provided options.
Instance Method Summary collapse
-
#|(other) ⇒ Hash
Implements the | (union) operator for hash-like objects.
Instance Method Details
#|(other) ⇒ Hash
The merge operation preserves the original hashes and returns a new
Implements the | (union) operator for hash-like objects.
Merges another hash-like object into this object, with the other taking precedence over self. This is useful for configuration merging where default values should be overridden by user-provided options.
hash. In case of duplicate keys, values from ‘other` will overwrite values from `self`.
50 51 52 53 54 55 56 57 58 |
# File 'lib/tins/hash_union.rb', line 50 def |(other) case when other.respond_to?(:to_hash) other = other.to_hash when other.respond_to?(:to_h) other = other.to_h end other.merge(self) end |