From 4d93f64264d16eba9e9fd16b7d7d1c8bd8c1880f Mon Sep 17 00:00:00 2001 From: Olle Jonsson Date: Wed, 29 Mar 2023 17:19:52 +0200 Subject: [PATCH] Ensure eval knows its whereabouts Use #each_key, add a separating newline, and meaningfully name heredoc markers. --- lib/sitemap_generator/templates.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/sitemap_generator/templates.rb b/lib/sitemap_generator/templates.rb index 78ec510e..6f37235b 100644 --- a/lib/sitemap_generator/templates.rb +++ b/lib/sitemap_generator/templates.rb @@ -9,17 +9,18 @@ module SitemapGenerator # Define an accessor method for each template file. class Templates FILES = { - :sitemap_sample => 'sitemap.rb', + :sitemap_sample => 'sitemap.rb', } # Dynamically define accessors for each key defined in FILES attr_accessor(*FILES.keys) - FILES.keys.each do |name| - eval <<-END + + FILES.each_key do |name| + eval(<<-ACCESSOR, binding, __FILE__ , __LINE__ + 1) define_method(:#{name}) do @#{name} ||= read_template(:#{name}) end - END + ACCESSOR end def initialize(root = SitemapGenerator.root)