Module: HashRecursiveMerge

Included in:
Hash
Defined in:
lib/lib/utils.rb

Instance Method Summary collapse

Instance Method Details

#rmerge(other_hash, concat_if_array = false) ⇒ Object



199
200
201
202
203
204
205
206
207
208
209
210
# File 'lib/lib/utils.rb', line 199

def rmerge(other_hash, concat_if_array = false)
  r = {}
  return merge(other_hash) do |key, oldval, newval|
    if oldval.is_a?(Hash)
      r[key] = oldval.rmerge(newval, concat_if_array)
    elsif oldval.is_a?(Array) and newval.is_a?(Array)
      r[key] = concat_if_array ? oldval + newval : newval
    else
      newval
    end
  end
end

#rmerge!(other_hash, concat_if_array = false) ⇒ Object



212
213
214
215
216
217
218
219
220
221
222
# File 'lib/lib/utils.rb', line 212

def rmerge!(other_hash, concat_if_array = false)
  return merge!(other_hash) do |key, oldval, newval|
    if oldval.is_a?(Hash)
      oldval.rmerge!(newval, concat_if_array)
    elsif oldval.is_a?(Array) and newval.is_a?(Array)
      concat_if_array ? oldval + newval : newval
    else
      newval
    end
  end
end