Merge pull request #2273 from jpiasetz/copy-rails-functions

This commit is contained in:
Parker Moore 2014-04-28 12:41:31 -04:00
commit 6be3084eac
1 changed files with 10 additions and 10 deletions

View File

@ -48,17 +48,21 @@ module Jekyll
array || []
end
def transform_keys(hash)
result = {}
hash.each_key do |key|
result[yield(key)] = hash[key]
end
result
end
# Apply #to_sym to all keys in the hash
#
# hash - the hash to which to apply this transformation
#
# Returns a new hash with symbolized keys
def symbolize_hash_keys(hash)
target = hash.dup
target.keys.each do |key|
target[(key.to_sym rescue key) || key] = target.delete(key)
end
target
transform_keys(hash) { |key| key.to_sym rescue key }
end
# Apply #to_s to all keys in the Hash
@ -67,11 +71,7 @@ module Jekyll
#
# Returns a new hash with stringified keys
def stringify_hash_keys(hash)
target = hash.dup
target.keys.each do |key|
target[(key.to_s rescue key) || key] = target.delete(key)
end
target
transform_keys(hash) { |key| key.to_s rescue key }
end
end