Method: Moneta::Defaults#merge!
- Defined in:
- lib/moneta/mixins.rb
#merge!(pairs, options = {}) ⇒ self #merge!(pairs, options = {}) {|key, old_value, new_value| ... } ⇒ self
Note:
Some adapters may implement this method atomically, or in two passes when a block is provided. The default implmentation uses #key?, #load and #store.
Stores the pairs in the key-value store, and returns itself. When a block is provided, it will be called before overwriting any existing values with the key, old value and supplied value, and the return value of the block will be used in place of the supplied value.
340 341 342 343 344 345 346 347 348 349 |
# File 'lib/moneta/mixins.rb', line 340 def merge!(pairs, = {}) pairs.each do |key, value| if block_given? existing = load(key, ) value = yield(key, existing, value) unless existing == nil end store(key, value, ) end self end |