Mutate hash literals instead of duplicating them (#417)

Merge pull request 417
This commit is contained in:
Ashwin Maroli 2020-10-07 21:21:32 +05:30 committed by GitHub
parent ae0f02f1e0
commit 76e062d734
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 8 deletions

View File

@ -78,7 +78,7 @@ module Jekyll
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

View File

@ -39,13 +39,17 @@ module Jekyll
# 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