From f0e24682491836a307ffee67c9726ea3c8293b96 Mon Sep 17 00:00:00 2001 From: "maul.esel" Date: Mon, 22 Jul 2013 16:02:42 +0200 Subject: [PATCH] simplify some code with Hash#fetch --- lib/jekyll/page.rb | 2 +- lib/jekyll/post.rb | 10 +++------- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/lib/jekyll/page.rb b/lib/jekyll/page.rb index 56119e07..5d1a9ea3 100644 --- a/lib/jekyll/page.rb +++ b/lib/jekyll/page.rb @@ -118,7 +118,7 @@ module Jekyll self.data.deep_merge({ "url" => self.url, "content" => self.content, - "path" => self.data['path'] || path }) + "path" => self.data.fetch('path', path) }) end # The path to the source file diff --git a/lib/jekyll/post.rb b/lib/jekyll/post.rb index 1b70e31e..411f54de 100644 --- a/lib/jekyll/post.rb +++ b/lib/jekyll/post.rb @@ -106,18 +106,14 @@ module Jekyll # # Returns excerpt string. def excerpt - if self.data.has_key? 'excerpt' - self.data['excerpt'] - else - self.extracted_excerpt.to_s - end + self.data.fetch('excerpt', self.extracted_excerpt.to_s) end # Public: the Post title, from the YAML Front-Matter or from the slug # # Returns the post title def title - self.data["title"] || self.slug.split('-').select {|w| w.capitalize! || w }.join(' ') + self.data.fetch("title", self.slug.split('-').select {|w| w.capitalize! || w }.join(' ')) end # Public: the path to the post relative to the site source, @@ -127,7 +123,7 @@ module Jekyll # # Returns the path to the file relative to the site source def path - self.data['path'] || File.join(@dir, '_posts', @name).sub(/\A\//, '') + self.data.fetch('path', File.join(@dir, '_posts', @name).sub(/\A\//, '')) end # Compares Post objects. First compares the Post date. If the dates are