Class: Hash

Inherits:
Object
  • Object
show all
Defined in:
lib/cl/magic/dk/yaml_arg_munger.rb

Overview

our dk hash merging process

Instance Method Summary collapse

Instance Method Details

#dk_merge(second) ⇒ Object



164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# File 'lib/cl/magic/dk/yaml_arg_munger.rb', line 164

def dk_merge(second)
  merger = proc { |_, v1, v2|
    if Hash === v1 && Hash === v2
      v1.merge(v2, &merger)
    else
      if Array === v1 && Array === v2
        if v2.first=="<dk-replace>"
          v2[1..-1] # everything but the first item
        else
          v1 | v2 # union arrays
        end
      else
        if [:undefined, nil, :nil].include?(v2)
          v1
        else
          v2
        end
      end
    end
  }
  merge(second.to_h, &merger)
end

#dk_reject!(&blk) ⇒ Object



186
187
188
189
190
191
# File 'lib/cl/magic/dk/yaml_arg_munger.rb', line 186

def dk_reject!(&blk)
  self.each do |k, v|
    v.dk_reject!(&blk)  if v.is_a?(Hash)
    self.delete(k)  if blk.call(k, v)
  end
end