Skip to content

Commit f4d3dae

Browse files
authored
Merge pull request #732 from casperisfine/3.x-fix-erb-version-checking
Better check for ERB keyword arguments
2 parents 4174470 + 7cfb0a0 commit f4d3dae

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

lib/sprockets/erb_processor.rb

+8-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ def initialize(&block)
1818
end
1919

2020
def call(input)
21-
match = ERB.version.match(/\Aerb\.rb \[(?<version>[^ ]+) /)
22-
if match && match[:version] >= "2.2.0" # Ruby 2.6+
21+
if keyword_constructor? # Ruby 2.6+
2322
engine = ::ERB.new(input[:data], trim_mode: '<>')
2423
else
2524
engine = ::ERB.new(input[:data], nil, '<>')
@@ -32,5 +31,12 @@ def call(input)
3231
data = context._evaluate_template
3332
context.metadata.merge(data: data)
3433
end
34+
35+
private
36+
37+
def keyword_constructor?
38+
return @keyword_constructor if defined? @keyword_constructor
39+
@keyword_constructor = ::ERB.instance_method(:initialize).parameters.include?([:key, :trim_mode])
40+
end
3541
end
3642
end

0 commit comments

Comments
 (0)