Skip to content

Commit

Permalink
Use delete_prefix instead of sub(/\Afixed-pattern/, '')
Browse files Browse the repository at this point in the history
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66189 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
znz committed Dec 4, 2018
1 parent a94cbf8 commit c01a5ee
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions ext/ripper/lib/ripper/lexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions lib/cgi/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/mkmf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion lib/net/protocol.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand Down
2 changes: 1 addition & 1 deletion lib/optparse.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/un.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c01a5ee

Please sign in to comment.