ruby-changes:50465
From: k0kubun <ko1@a...>
Date: Tue, 27 Feb 2018 20:12:29 +0900 (JST)
Subject: [ruby-changes:50465] k0kubun:r62594 (trunk): Refactor ERB version checking for keyword arguments
k0kubun 2018-02-27 20:12:23 +0900 (Tue, 27 Feb 2018) New Revision: 62594 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=62594 Log: Refactor ERB version checking for keyword arguments Improving code like r62590. See r62529 for details. Modified files: trunk/enc/make_encmake.rb trunk/ext/etc/mkconstants.rb trunk/ext/socket/mkconstants.rb trunk/tool/generic_erb.rb trunk/tool/ruby_vm/helpers/dumper.rb trunk/tool/transcode-tblgen.rb Index: enc/make_encmake.rb =================================================================== --- enc/make_encmake.rb (revision 62593) +++ enc/make_encmake.rb (revision 62594) @@ -121,7 +121,7 @@ ENCS, ENC_DEPS = target_encodings https://github.com/ruby/ruby/blob/trunk/enc/make_encmake.rb#L121 ATRANS, TRANS = target_transcoders if File.exist?(depend = File.join($srcdir, "depend")) - if ERB.version[/\d+\.\d+/] >= '2.2' + if ERB.instance_method(:initialize).parameters.assoc(:key) # Ruby 2.6+ erb = ERB.new(File.read(depend), trim_mode: '%') else erb = ERB.new(File.read(depend), nil, '%') @@ -139,7 +139,7 @@ open(ARGV[0], 'wb') {|f| https://github.com/ruby/ruby/blob/trunk/enc/make_encmake.rb#L139 } if MODULE_TYPE == :static filename = "encinit.c.erb" - if ERB.version[/\d+\.\d+/] >= '2.2' + if ERB.instance_method(:initialize).parameters.assoc(:key) # Ruby 2.6+ erb = ERB.new(File.read(File.join($srcdir, filename)), trim_mode: '%-') else erb = ERB.new(File.read(File.join($srcdir, filename)), nil, '%-') Index: tool/generic_erb.rb =================================================================== --- tool/generic_erb.rb (revision 62593) +++ tool/generic_erb.rb (revision 62594) @@ -34,8 +34,7 @@ unchanged = color.pass("unchanged") https://github.com/ruby/ruby/blob/trunk/tool/generic_erb.rb#L34 updated = color.fail("updated") result = templates.map do |template| - match = ERB.version.match(/\Aerb\.rb \[(?<version>[^ ]+) /) - if match && match[:version] >= '2.2.0' # Ruby 2.6+ + if ERB.instance_method(:initialize).parameters.assoc(:key) # Ruby 2.6+ erb = ERB.new(File.read(template), trim_mode: '%-') else erb = ERB.new(File.read(template), nil, '%-') Index: tool/ruby_vm/helpers/dumper.rb =================================================================== --- tool/ruby_vm/helpers/dumper.rb (revision 62593) +++ tool/ruby_vm/helpers/dumper.rb (revision 62594) @@ -32,8 +32,7 @@ class RubyVM::Dumper https://github.com/ruby/ruby/blob/trunk/tool/ruby_vm/helpers/dumper.rb#L32 rescue Errno::ENOENT raise "don't know how to generate #{path}" else - match = ERB.version.match(/\Aerb\.rb \[(?<version>[^ ]+) /) - if match && match[:version] >= '2.2.0' # Ruby 2.6+ + if ERB.instance_method(:initialize).parameters.assoc(:key) # Ruby 2.6+ erb = ERB.new(src, trim_mode: '%-') else erb = ERB.new(src, nil, '%-') Index: tool/transcode-tblgen.rb =================================================================== --- tool/transcode-tblgen.rb (revision 62593) +++ tool/transcode-tblgen.rb (revision 62594) @@ -1078,7 +1078,7 @@ if __FILE__ == $0 https://github.com/ruby/ruby/blob/trunk/tool/transcode-tblgen.rb#L1078 end libs1 = $".dup - if ERB.version[/\d+\.\d+/] >= '2.2' + if ERB.instance_method(:initialize).parameters.assoc(:key) # Ruby 2.6+ erb = ERB.new(src, trim_mode: '%') else erb = ERB.new(src, nil, '%') Index: ext/etc/mkconstants.rb =================================================================== --- ext/etc/mkconstants.rb (revision 62593) +++ ext/etc/mkconstants.rb (revision 62594) @@ -67,7 +67,7 @@ def each_name(pat) https://github.com/ruby/ruby/blob/trunk/ext/etc/mkconstants.rb#L67 end erb_new = lambda do |src, safe, trim| - if RUBY_VERSION >= '2.6' + if ERB.instance_method(:initialize).parameters.assoc(:key) # Ruby 2.6+ ERB.new(src, trim_mode: trim) else ERB.new(src, safe, trim) Index: ext/socket/mkconstants.rb =================================================================== --- ext/socket/mkconstants.rb (revision 62593) +++ ext/socket/mkconstants.rb (revision 62594) @@ -74,7 +74,7 @@ def each_name(pat) https://github.com/ruby/ruby/blob/trunk/ext/socket/mkconstants.rb#L74 end erb_new = lambda do |src, safe, trim| - if RUBY_VERSION >= '2.6' + if ERB.instance_method(:initialize).parameters.assoc(:key) # Ruby 2.6+ ERB.new(src, trim_mode: trim) else ERB.new(src, safe, trim) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/