Skip to content

Commit

Permalink
[ruby/yarp] Switch ERB.new at startup
Browse files Browse the repository at this point in the history
  • Loading branch information
nobu authored and matzbot committed Sep 5, 2023
1 parent e1713fa commit 89a4fd6
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions yarp/templates/template.rb
Expand Up @@ -266,7 +266,6 @@ def template(name, write_to: nil)
template = File.expand_path("../#{filepath}", __dir__)

erb = read_template(template)
erb.filename = template

non_ruby_heading = <<~HEADING
/******************************************************************************/
Expand Down Expand Up @@ -305,9 +304,17 @@ def template(name, write_to: nil)

def read_template(filepath)
template = File.read(filepath, encoding: Encoding::UTF_8)
if ERB.instance_method(:initialize).parameters.assoc(:key) # Ruby 2.6+
erb = erb(template)
erb.filename = filepath
erb
end

if ERB.instance_method(:initialize).parameters.assoc(:key) # Ruby 2.6+
def erb(template)
ERB.new(template, trim_mode: "-")
else
end
else
def erb
ERB.new(template, nil, "-")
end
end
Expand Down

0 comments on commit 89a4fd6

Please sign in to comment.