From c76e41d157cf239e14384351b61472e50073c1fc Mon Sep 17 00:00:00 2001 From: Terry Schmidt Date: Tue, 20 May 2014 12:32:59 -0500 Subject: [PATCH] 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`. --- lib/jekyll/utils.rb | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/jekyll/utils.rb b/lib/jekyll/utils.rb index 6dab6127..e1b4704d 100644 --- a/lib/jekyll/utils.rb +++ b/lib/jekyll/utils.rb @@ -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)