mirror of
https://github.com/jekyll/jekyll.git
synced 2026-01-31 17:58:29 -05:00
Update Utils#pluralized_array_from_hash and Utils#value_from_singular_key per suggestion from @parkr
Switched to using the `#tap` method for more concise code. Also returning the value from `value_from_singular_key` instead of returning an array wrapped presentation of the value. This allows for a one-liner in `pluralized_array_from_hash`.
This commit is contained in:
@@ -35,14 +35,13 @@ module Jekyll
|
||||
#
|
||||
# Returns an array
|
||||
def pluralized_array_from_hash(hash, singular_key, plural_key)
|
||||
array = []
|
||||
array << value_from_singular_key(hash, singular_key)
|
||||
array << value_from_plural_key(hash, plural_key) if array.flatten.compact.empty?
|
||||
array.flatten.compact
|
||||
[].tap do |array|
|
||||
array << (value_from_singular_key(hash, singular_key) || value_from_plural_key(hash, plural_key))
|
||||
end.flatten.compact
|
||||
end
|
||||
|
||||
def value_from_singular_key(hash, key)
|
||||
[hash[key]] if hash.has_key?(key) || (hash.default_proc && hash[key])
|
||||
hash[key] if (hash.has_key?(key) || (hash.default_proc && hash[key]))
|
||||
end
|
||||
|
||||
def value_from_plural_key(hash, key)
|
||||
|
||||
Reference in New Issue
Block a user