Reduce Array objects generated from utility method (#7749)

Merge pull request 7749
This commit is contained in:
Ashwin Maroli 2019-07-12 20:14:45 +05:30 committed by jekyllbot
parent 77b6033f2f
commit 135ebe2660
1 changed files with 8 additions and 5 deletions

View File

@ -68,11 +68,14 @@ module Jekyll
# #
# Returns an array # Returns an array
def pluralized_array_from_hash(hash, singular_key, plural_key) def pluralized_array_from_hash(hash, singular_key, plural_key)
[].tap do |array| array = []
value = value_from_singular_key(hash, singular_key) value = value_from_singular_key(hash, singular_key)
value ||= value_from_plural_key(hash, plural_key) value ||= value_from_plural_key(hash, plural_key)
array << value
end.flatten.compact array << value
array.flatten!
array.compact!
array
end end
def value_from_singular_key(hash, key) def value_from_singular_key(hash, key)