From c01a5ee85e2d6a7128cccafb143bfa694284ca87 Mon Sep 17 00:00:00 2001 From: kazu Date: Tue, 4 Dec 2018 08:22:10 +0000 Subject: Use delete_prefix instead of `sub(/\Afixed-pattern/, '')` git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66189 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/cgi/core.rb | 4 ++-- lib/mkmf.rb | 2 +- lib/net/protocol.rb | 2 +- lib/optparse.rb | 2 +- lib/un.rb | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/cgi/core.rb b/lib/cgi/core.rb index 3fb8dbab54..c45f9b3a9e 100644 --- a/lib/cgi/core.rb +++ b/lib/cgi/core.rb @@ -421,7 +421,7 @@ class CGI module QueryExtension %w[ CONTENT_LENGTH SERVER_PORT ].each do |env| - define_method(env.sub(/^HTTP_/, '').downcase) do + define_method(env.delete_prefix('HTTP_').downcase) do (val = env_table[env]) && Integer(val) end end @@ -434,7 +434,7 @@ class CGI HTTP_ACCEPT HTTP_ACCEPT_CHARSET HTTP_ACCEPT_ENCODING HTTP_ACCEPT_LANGUAGE HTTP_CACHE_CONTROL HTTP_FROM HTTP_HOST HTTP_NEGOTIATE HTTP_PRAGMA HTTP_REFERER HTTP_USER_AGENT ].each do |env| - define_method(env.sub(/^HTTP_/, '').downcase) do + define_method(env.delete_prefix('HTTP_').downcase) do env_table[env] end end diff --git a/lib/mkmf.rb b/lib/mkmf.rb index 355ea171ee..0d9d3d9f38 100644 --- a/lib/mkmf.rb +++ b/lib/mkmf.rb @@ -2264,7 +2264,7 @@ RULES origdef ||= '' if $extout and $INSTALLFILES - $cleanfiles.concat($INSTALLFILES.collect {|files, dir|File.join(dir, files.sub(/\A\.\//, ''))}) + $cleanfiles.concat($INSTALLFILES.collect {|files, dir|File.join(dir, files.delete_prefix('./'))}) $distcleandirs.concat($INSTALLFILES.collect {|files, dir| dir}) end diff --git a/lib/net/protocol.rb b/lib/net/protocol.rb index 037fcd8358..71378af804 100644 --- a/lib/net/protocol.rb +++ b/lib/net/protocol.rb @@ -311,7 +311,7 @@ module Net # :nodoc: read_bytes = 0 while (line = readuntil("\r\n")) != ".\r\n" read_bytes += line.size - yield line.sub(/\A\./, '') + yield line.delete_prefix('.') end LOG_on() LOG "read message (#{read_bytes} bytes)" diff --git a/lib/optparse.rb b/lib/optparse.rb index c6e652971e..5cdcabf4a7 100644 --- a/lib/optparse.rb +++ b/lib/optparse.rb @@ -1595,7 +1595,7 @@ XXX begin sw, = complete(:short, opt) # short option matched. - val = arg.sub(/\A-/, '') + val = arg.delete_prefix('-') has_arg = true rescue InvalidOption # if no short options match, try completion with long diff --git a/lib/un.rb b/lib/un.rb index d109a3417b..14f5b10fec 100644 --- a/lib/un.rb +++ b/lib/un.rb @@ -47,7 +47,7 @@ def setup(options = "", *long_options) end long_options.each do |s| opt_name, arg_name = s.split(/(?=[\s=])/, 2) - opt_name.sub!(/\A--/, '') + opt_name.delete_prefix!('--') s = "--#{opt_name.gsub(/([A-Z]+|[a-z])([A-Z])/, '\1-\2').downcase}#{arg_name}" puts "#{opt_name}=>#{s}" if $DEBUG opt_name = opt_name.intern -- cgit v1.2.3