diff --git a/ext/ripper/lib/ripper/lexer.rb b/ext/ripper/lib/ripper/lexer.rb index ece71dd466442a..344328482b83a8 100644 --- a/ext/ripper/lib/ripper/lexer.rb +++ b/ext/ripper/lib/ripper/lexer.rb @@ -207,14 +207,14 @@ def compile(pattern) 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) diff --git a/lib/cgi/core.rb b/lib/cgi/core.rb index 3fb8dbab542333..c45f9b3a9e8ed4 100644 --- a/lib/cgi/core.rb +++ b/lib/cgi/core.rb @@ -421,7 +421,7 @@ def CGI::parse(query) 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 @@ module QueryExtension 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 355ea171ee8adc..0d9d3d9f387d2f 100644 --- a/lib/mkmf.rb +++ b/lib/mkmf.rb @@ -2264,7 +2264,7 @@ def create_makefile(target, srcprefix = nil) 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 037fcd83588698..71378af8044386 100644 --- a/lib/net/protocol.rb +++ b/lib/net/protocol.rb @@ -311,7 +311,7 @@ def each_message_chunk 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 c6e652971ea8a8..5cdcabf4a75571 100644 --- a/lib/optparse.rb +++ b/lib/optparse.rb @@ -1595,7 +1595,7 @@ def parse_in_order(argv = default_argv, setter = nil, &nonopt) # :nodoc: 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 d109a3417bb002..14f5b10feccffa 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