Skip to content

Commit

Permalink
Mutate hash literals instead of duplicating them (#417)
Browse files Browse the repository at this point in the history
Merge pull request 417
  • Loading branch information
ashmaroli authored Oct 7, 2020
1 parent ae0f02f commit 76e062d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/jekyll-seo-tag/author_drop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def author_hash
if resolved_author.is_a? Hash
resolved_author
elsif resolved_author.is_a? String
{ "name" => resolved_author }.merge(site_data_hash)
{ "name" => resolved_author }.merge!(site_data_hash)
else
{}
end
Expand Down
18 changes: 11 additions & 7 deletions lib/jekyll-seo-tag/image_drop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,17 @@ def path

# The normalized image hash with a `path` key (which may be nil)
def image_hash
@image_hash ||= if page["image"].is_a?(Hash)
{ "path" => nil }.merge(page["image"])
elsif page["image"].is_a?(String)
{ "path" => page["image"] }
else
{ "path" => nil }
end
@image_hash ||= begin
image_meta = page["image"]

if image_meta.is_a?(Hash)
{ "path" => nil }.merge!(image_meta)
elsif image_meta.is_a?(String)
{ "path" => image_meta }
else
{ "path" => nil }
end
end
end
alias_method :fallback_data, :image_hash

Expand Down

0 comments on commit 76e062d

Please # to comment.