Code cleanup

This commit is contained in:
Brendan Coles
2018-06-11 11:36:35 +00:00
parent 21af0ae705
commit 1dea97511b
15 changed files with 689 additions and 558 deletions

View File

@@ -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]

View File

@@ -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