module Percolate::Util
Contains utility methods.
Public Class Methods
merge_attributes(lhs, rhs)
click to toggle source
Merges the given attributes, which can take the form of nested `Hash`es, `Array`s, and `String`s. If there is a conflict, the right hand side wins.
# File lib/percolate/util.rb, line 23 def self.merge_attributes(lhs, rhs) if lhs.is_a?(Hash) && rhs.is_a?(Hash) res = {} lhs.each_pair do |key, value| if rhs.include?(key) res[key] = merge_attributes(lhs[key], rhs[key]) else res[key] = value end end rhs.each_pair do |key, value| res[key] = value if !res.include?(key) end elsif lhs.is_a?(Array) && rhs.is_a?(Array) res = lhs + rhs else res = rhs end res end