@chad :+1: best of both worlds. thanks for the extra pair of eyes


On Sun, Apr 28, 2013 at 6:31 AM, Chad Fowler <notifications@github.com>wrote:

> In lib/jekyll/post.rb:
>
> > @@ -302,6 +315,17 @@ def previous
> >
> >      protected
> >
> > +    # Protected: Fetch a Hash of specified attributes which has a corresponding
> > +    #            method: title, url, date, id, categories, next, previous, tags,
> > +    #            content, excerpt, and path
> > +    #
> > +    # Returns a hash of the attributes and their values
> > +    def methods_as_hash_for_liquid
>
> I haven't looked at this code before, but I would say that the original
> implementation was rife with duplication. It also used unnecessary calls on
> the explicit receiver (self).
>
> Maybe I'm strange, but the little method that generates the Hash in the
> new version doesn't look unclear at all to me. It clearly generates a hash
> out of the values of all of the methods passed to it.
>
> I would probably do something in between the version in this commit and
> the comment:
>
> ATTRIBUTES_FOR_LIQUID = %w(
>   title  url  date  id  categories  next  previous  tags  content  excerpt  path
> )def to_liquid
>   further_data = Hash[ATTRIBUTES_FOR_LIQUID].map { |attribute|
>     [attribute, send(attribute)]
>   }]
>   data.deep_merge(further_data)end
>
> Also note that you don't need the #to_sym call for send.
>
> —
> Reply to this email directly or view it on GitHub<https://github.com/mojombo/jekyll/pull/1002/files#r3991180>
> .
>