ruby-changes:53969
From: kazu <ko1@a...>
Date: Tue, 4 Dec 2018 17:22:15 +0900 (JST)
Subject: [ruby-changes:53969] kazu:r66189 (trunk): Use delete_prefix instead of `sub(/\Afixed-pattern/, '')`
kazu 2018-12-04 17:22:10 +0900 (Tue, 04 Dec 2018) New Revision: 66189 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=66189 Log: Use delete_prefix instead of `sub(/\Afixed-pattern/, '')` Modified files: trunk/ext/ripper/lib/ripper/lexer.rb trunk/lib/cgi/core.rb trunk/lib/mkmf.rb trunk/lib/net/protocol.rb trunk/lib/optparse.rb trunk/lib/un.rb Index: lib/mkmf.rb =================================================================== --- lib/mkmf.rb (revision 66188) +++ lib/mkmf.rb (revision 66189) @@ -2264,7 +2264,7 @@ RULES https://github.com/ruby/ruby/blob/trunk/lib/mkmf.rb#L2264 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 Index: lib/optparse.rb =================================================================== --- lib/optparse.rb (revision 66188) +++ lib/optparse.rb (revision 66189) @@ -1595,7 +1595,7 @@ XXX https://github.com/ruby/ruby/blob/trunk/lib/optparse.rb#L1595 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 Index: lib/cgi/core.rb =================================================================== --- lib/cgi/core.rb (revision 66188) +++ lib/cgi/core.rb (revision 66189) @@ -421,7 +421,7 @@ class CGI https://github.com/ruby/ruby/blob/trunk/lib/cgi/core.rb#L421 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 https://github.com/ruby/ruby/blob/trunk/lib/cgi/core.rb#L434 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 Index: lib/un.rb =================================================================== --- lib/un.rb (revision 66188) +++ lib/un.rb (revision 66189) @@ -47,7 +47,7 @@ def setup(options = "", *long_options) https://github.com/ruby/ruby/blob/trunk/lib/un.rb#L47 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 Index: lib/net/protocol.rb =================================================================== --- lib/net/protocol.rb (revision 66188) +++ lib/net/protocol.rb (revision 66189) @@ -311,7 +311,7 @@ module Net # :nodoc: https://github.com/ruby/ruby/blob/trunk/lib/net/protocol.rb#L311 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)" Index: ext/ripper/lib/ripper/lexer.rb =================================================================== --- ext/ripper/lib/ripper/lexer.rb (revision 66188) +++ ext/ripper/lib/ripper/lexer.rb (revision 66189) @@ -207,14 +207,14 @@ class Ripper https://github.com/ruby/ruby/blob/trunk/ext/ripper/lib/ripper/lexer.rb#L207 end def map_tokens(tokens) - tokens.map {|pos,type,str| map_token(type.to_s.sub(/\Aon_/,'')) }.join + tokens.map {|pos,type,str| map_token(type.to_s.delete_prefix('on_')) }.join end MAP = {} seed = ('a'..'z').to_a + ('A'..'Z').to_a + ('0'..'9').to_a SCANNER_EVENT_TABLE.each do |ev, | raise CompileError, "[RIPPER FATAL] too many system token" if seed.empty? - MAP[ev.to_s.sub(/\Aon_/,'')] = seed.shift + MAP[ev.to_s.delete_prefix('on_')] = seed.shift end def map_token(tok) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/