Code cleanup
This commit is contained in:
@@ -8,13 +8,14 @@ class Hash
|
||||
# Recursively deep merge two hashes together
|
||||
# @param [Hash] hash Hash to be merged
|
||||
# @return [Hash] Combined hash
|
||||
# @note Duplicate keys are overwritten by the value defined in the hash calling deep_merge (not the parameter hash)
|
||||
# @note Duplicate keys are overwritten by the value defined
|
||||
# in the hash calling deep_merge (not the parameter hash)
|
||||
# @note http://snippets.dzone.com/posts/show/4706
|
||||
def deep_merge(hash)
|
||||
target = dup
|
||||
hash.keys.each do |key|
|
||||
if hash[key].is_a? Hash and self[key].is_a? Hash
|
||||
target[key] = target[key].deep_merge(hash[key])
|
||||
if hash[key].is_a?(Hash) && self[key].is_a?(Hash)
|
||||
target[key] = target[key].deep_merge hash[key]
|
||||
next
|
||||
end
|
||||
target[key] = hash[key]
|
||||
|
||||
@@ -35,4 +35,9 @@ class Object
|
||||
self.is_a?(Class)
|
||||
end
|
||||
|
||||
# Returns true if the object is nil, and empty string, or empty array
|
||||
# @return [Boolean]
|
||||
def blank?
|
||||
self.respond_to?(:empty?) ? !!empty? : !self
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user