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



157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/lib/utils.rb', line 157

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



170
171
172
173
174
175
176
177
178
179
180
# File 'lib/lib/utils.rb', line 170

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