From f02f035d0127a8c6f9eba5af24dcdc4c22844624 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=20Ondruch?= Date: Thu, 4 Aug 2022 13:05:00 +0200 Subject: [PATCH] Use introspection to detect usage of kwargs/positional args. This avoids checking of Ruby version, which is almost never the right thing. --- lib/gem2rpm.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/gem2rpm.rb b/lib/gem2rpm.rb index 824f5bf..5f20a31 100644 --- a/lib/gem2rpm.rb +++ b/lib/gem2rpm.rb @@ -90,7 +90,10 @@ def self.convert(fname, template, out = $stdout, nongem = true, local = false, end end - erb = if RUBY_VERSION >= '2.6' + # Check if keyword arguments are used. The condition could let go as soon + # as only Ruby 2.6+ is supported. + kwargs = !(ERB.new("").method(:initialize).parameters & [[:key, :trim_mode]]).empty? + erb = if kwargs ERB.new(template.read, trim_mode: '-') else ERB.new(template.read, 0, '-')