Skip to content

Commit

Permalink
Ensure eval knows its whereabouts
Browse files Browse the repository at this point in the history
Use #each_key, add a separating newline, and meaningfully name heredoc markers.
  • Loading branch information
olleolleolle committed Nov 4, 2024
1 parent b092f04 commit 4d93f64
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/sitemap_generator/templates.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 <tt>FILES</tt>
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)
Expand Down

0 comments on commit 4d93f64

Please sign in to comment.