diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/date/format.rb | 6 | ||||
-rw-r--r-- | lib/irb/context.rb | 2 | ||||
-rw-r--r-- | lib/irb/workspace.rb | 2 | ||||
-rw-r--r-- | lib/net/http.rb | 2 | ||||
-rw-r--r-- | lib/net/imap.rb | 4 | ||||
-rw-r--r-- | lib/rdoc/generator.rb | 6 | ||||
-rw-r--r-- | lib/rdoc/markup/to_html.rb | 6 | ||||
-rw-r--r-- | lib/rdoc/markup/to_latex.rb | 6 | ||||
-rw-r--r-- | lib/rdoc/parsers/parse_c.rb | 2 | ||||
-rw-r--r-- | lib/rdoc/ri/formatter.rb | 30 | ||||
-rw-r--r-- | lib/rexml/parsers/baseparser.rb | 2 | ||||
-rw-r--r-- | lib/rexml/quickpath.rb | 9 | ||||
-rw-r--r-- | lib/rexml/text.rb | 5 | ||||
-rw-r--r-- | lib/rss/parser.rb | 4 | ||||
-rw-r--r-- | lib/uri/common.rb | 3 | ||||
-rw-r--r-- | lib/uri/generic.rb | 2 | ||||
-rw-r--r-- | lib/webrick/httpresponse.rb | 2 | ||||
-rw-r--r-- | lib/webrick/httpservlet/filehandler.rb | 2 | ||||
-rw-r--r-- | lib/yaml/baseemitter.rb | 2 | ||||
-rw-r--r-- | lib/yaml/encoding.rb | 6 |
20 files changed, 50 insertions, 53 deletions
diff --git a/lib/date/format.rb b/lib/date/format.rb index 3b152b65ba..46d2147b89 100644 --- a/lib/date/format.rb +++ b/lib/date/format.rb @@ -215,9 +215,9 @@ class Date :emit_a, :emit_ad, :emit_au def strftime(fmt='%F') - fmt.gsub(/%([-_0^#]+)?(\d+)?([EO]?(?::{1,3}z|.))/m) do |m| + fmt.gsub(/%([-_0^#]+)?(\d+)?([EO]?(?::{1,3}z|.))/m) do f = {} - a = $& + m = $& s, w, c = $1, $2, $3 if s s.scan(/./) do |k| @@ -327,7 +327,7 @@ class Date when '%'; emit_a('%', 0, f) when '+'; emit_a(strftime('%a %b %e %H:%M:%S %Z %Y'), 0, f) else - a + m end end end diff --git a/lib/irb/context.rb b/lib/irb/context.rb index b6ffaacb31..6a5e77fb70 100644 --- a/lib/irb/context.rb +++ b/lib/irb/context.rb @@ -233,7 +233,7 @@ module IRB def inspect array = [] for ivar in instance_variables.sort{|e1, e2| e1 <=> e2} - name = ivar.sub(/^@(.*)$/){$1} + name = ivar.sub(/^@(.*)$/, '\1') val = instance_eval(ivar) case ivar when *NOPRINTING_IVARS diff --git a/lib/irb/workspace.rb b/lib/irb/workspace.rb index 8ac44861d5..c27f7052d1 100644 --- a/lib/irb/workspace.rb +++ b/lib/irb/workspace.rb @@ -95,7 +95,7 @@ EOF return nil if bt =~ /irb\/.*\.rb/ when 3 return nil if bt =~ /irb\/.*\.rb/ - bt.sub!(/:\s*in `irb_binding'/){""} + bt.sub!(/:\s*in `irb_binding'/, '') end bt end diff --git a/lib/net/http.rb b/lib/net/http.rb index 06b176b3c6..d3e3d9f2f5 100644 --- a/lib/net/http.rb +++ b/lib/net/http.rb @@ -1521,7 +1521,7 @@ module Net #:nodoc: private :encode_kvpair def urlencode(str) - str.gsub(/[^a-zA-Z0-9_\.\-]/n) {|s| sprintf('%%%02x', s[0]) } + str.gsub(/[^a-zA-Z0-9_\.\-]/n) { sprintf('%%%02x', $&[0]) } end private :urlencode diff --git a/lib/net/imap.rb b/lib/net/imap.rb index 394f0d9890..016f567b07 100644 --- a/lib/net/imap.rb +++ b/lib/net/imap.rb @@ -857,11 +857,11 @@ module Net # Encode a string from UTF-8 format to modified UTF-7. def self.encode_utf7(s) - return s.gsub(/(&)|([^\x20-\x25\x27-\x7e]+)/u) { |x| + return s.gsub(/(&)|([^\x20-\x25\x27-\x7e]+)/u) { if $1 "&-" else - base64 = [x.unpack("U*").pack("n*")].pack("m") + base64 = [$&.unpack("U*").pack("n*")].pack("m") "&" + base64.delete("=\n").tr("/", ",") + "-" end }.force_encoding("ASCII-8BIT") diff --git a/lib/rdoc/generator.rb b/lib/rdoc/generator.rb index b62cd00506..0e5b4a8cc0 100644 --- a/lib/rdoc/generator.rb +++ b/lib/rdoc/generator.rb @@ -523,7 +523,7 @@ module RDoc::Generator def http_url(full_name, prefix) path = full_name.dup - path.gsub!(/<<\s*(\w*)/) { "from-#$1" } if path['<<'] + path.gsub!(/<<\s*(\w*)/, 'from-\1') if path['<<'] ::File.join(prefix, path.split("::")) + ".html" end @@ -704,8 +704,8 @@ module RDoc::Generator end def filename_to_label - @context.file_relative_name.gsub(/%|\/|\?|\#/) do |s| - '%%%x' % s[0].unpack('C') + @context.file_relative_name.gsub(/%|\/|\?|\#/) do + '%%%x' % $&[0].unpack('C') end end diff --git a/lib/rdoc/markup/to_html.rb b/lib/rdoc/markup/to_html.rb index da42312ff5..4fe16f8e91 100644 --- a/lib/rdoc/markup/to_html.rb +++ b/lib/rdoc/markup/to_html.rb @@ -200,14 +200,14 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter gsub(/\.\.\.\./, '.…').gsub(/\.\.\./, '…'). # convert single closing quote - gsub(%r{([^ \t\r\n\[\{\(])\'}) { "#$1’" }. - gsub(%r{\'(?=\W|s\b)}) { "’" }. + gsub(%r{([^ \t\r\n\[\{\(])\'}, '\1’'). + gsub(%r{\'(?=\W|s\b)}, '’'). # convert single opening quote gsub(/'/, '‘'). # convert double closing quote - gsub(%r{([^ \t\r\n\[\{\(])\'(?=\W)}) { "#$1”" }. + gsub(%r{([^ \t\r\n\[\{\(])\'(?=\W)}, '\1”'). # convert double opening quote gsub(/'/, '“'). diff --git a/lib/rdoc/markup/to_latex.rb b/lib/rdoc/markup/to_latex.rb index a679b3b06e..bbf958f2ed 100644 --- a/lib/rdoc/markup/to_latex.rb +++ b/lib/rdoc/markup/to_latex.rb @@ -227,14 +227,14 @@ class RDoc::Markup::ToLaTeX < RDoc::Markup::Formatter gsub(/\.\.\.\./, '.\ldots{}').gsub(/\.\.\./, '\ldots{}'). # convert single closing quote - gsub(%r{([^ \t\r\n\[\{\(])\'}) { "#$1'" }. - gsub(%r{\'(?=\W|s\b)}) { "'" }. + gsub(%r{([^ \t\r\n\[\{\(])\'}, '\1\''). + gsub(%r{\'(?=\W|s\b)}, "'" ). # convert single opening quote gsub(/'/, '`'). # convert double closing quote - gsub(%r{([^ \t\r\n\[\{\(])\"(?=\W)}) { "#$1''" }. + gsub(%r{([^ \t\r\n\[\{\(])\"(?=\W)}, "\\1''"). # convert double opening quote gsub(/"/, "``"). diff --git a/lib/rdoc/parsers/parse_c.rb b/lib/rdoc/parsers/parse_c.rb index 07d65bc9d8..5771250cb9 100644 --- a/lib/rdoc/parsers/parse_c.rb +++ b/lib/rdoc/parsers/parse_c.rb @@ -766,7 +766,7 @@ module RDoc # Removes #ifdefs that would otherwise confuse us def handle_ifdefs_in(body) - body.gsub(/^#ifdef HAVE_PROTOTYPES.*?#else.*?\n(.*?)#endif.*?\n/m) { $1 } + body.gsub(/^#ifdef HAVE_PROTOTYPES.*?#else.*?\n(.*?)#endif.*?\n/m, '\1') end end diff --git a/lib/rdoc/ri/formatter.rb b/lib/rdoc/ri/formatter.rb index d88cef1e3c..df73bf5eb3 100644 --- a/lib/rdoc/ri/formatter.rb +++ b/lib/rdoc/ri/formatter.rb @@ -87,22 +87,22 @@ class RDoc::RI::Formatter # Convert HTML entities back to ASCII def conv_html(txt) - txt. - gsub(/>/, '>'). - gsub(/</, '<'). - gsub(/"/, '"'). - gsub(/&/, '&') + txt = txt.gsub(/>/, '>') + txt.gsub!(/</, '<') + txt.gsub!(/"/, '"') + txt.gsub!(/&/, '&') + txt end ## # Convert markup into display form def conv_markup(txt) - txt. - gsub(%r{<tt>(.*?)</tt>}) { "+#$1+" } . - gsub(%r{<code>(.*?)</code>}) { "+#$1+" } . - gsub(%r{<b>(.*?)</b>}) { "*#$1*" } . - gsub(%r{<em>(.*?)</em>}) { "_#$1_" } + txt = txt.gsub(%r{<tt>(.*?)</tt>}, '+\1+') + txt.gsub!(%r{<code>(.*?)</code>}, '+\1+') + txt.gsub!(%r{<b>(.*?)</b>}, '*\1*') + txt.gsub!(%r{<em>(.*?)</em>}, '_\1_') + txt end def display_list(list) @@ -548,11 +548,11 @@ class RDoc::RI::HtmlFormatter < RDoc::RI::AttributeFormatter end def escape(str) - str. - gsub(/&/n, '&'). - gsub(/\"/n, '"'). - gsub(/>/n, '>'). - gsub(/</n, '<') + str = str.gsub(/&/n, '&') + str.gsub!(/\"/n, '"') + str.gsub!(/>/n, '>') + str.gsub!(/</n, '<') + str end end diff --git a/lib/rexml/parsers/baseparser.rb b/lib/rexml/parsers/baseparser.rb index 85f2c4e46d..162d029a62 100644 --- a/lib/rexml/parsers/baseparser.rb +++ b/lib/rexml/parsers/baseparser.rb @@ -482,7 +482,7 @@ module REXML rv.gsub!( /\r\n?/, "\n" ) matches = rv.scan( REFERENCE_RE ) return rv if matches.size == 0 - rv.gsub!( /�*((?:\d+)|(?:x[a-fA-F0-9]+));/ ) {|m| + rv.gsub!( /�*((?:\d+)|(?:x[a-fA-F0-9]+));/ ) { m=$1 m = "0#{m}" if m[0] == ?x [Integer(m)].pack('U*') diff --git a/lib/rexml/quickpath.rb b/lib/rexml/quickpath.rb index c099db8579..cdf4c53017 100644 --- a/lib/rexml/quickpath.rb +++ b/lib/rexml/quickpath.rb @@ -170,15 +170,12 @@ module REXML rest = path[ind+1..-1] # have to change 'a [=<>] b [=<>] c' into 'a [=<>] b and b [=<>] c' - predicate.gsub!( /([^\s(and)(or)<>=]+)\s*([<>=])\s*([^\s(and)(or)<>=]+)\s*([<>=])\s*([^\s(and)(or)<>=]+)/u ) { - "#$1 #$2 #$3 and #$3 #$4 #$5" - } + predicate.gsub!( /([^\s(and)(or)<>=]+)\s*([<>=])\s*([^\s(and)(or)<>=]+)\s*([<>=])\s*([^\s(and)(or)<>=]+)/u, + '\1 \2 \3 and \3 \4 \5' ) # Let's do some Ruby trickery to avoid some work: predicate.gsub!( /&/u, "&&" ) predicate.gsub!( /=/u, "==" ) - predicate.gsub!( /@(\w[-\w.]*)/u ) { - "attribute(\"#$1\")" - } + predicate.gsub!( /@(\w[-\w.]*)/u, 'attribute("\1")' ) predicate.gsub!( /\bmod\b/u, "%" ) predicate.gsub!( /\b(\w[-\w.]*\()/u ) { fname = $1 diff --git a/lib/rexml/text.rb b/lib/rexml/text.rb index 73a72ae527..8bc87dbf32 100644 --- a/lib/rexml/text.rb +++ b/lib/rexml/text.rb @@ -345,7 +345,7 @@ module REXML copy.gsub!( SETUTITSBUS[2], SLAICEPS[2] ) copy.gsub!( SETUTITSBUS[3], SLAICEPS[3] ) copy.gsub!( SETUTITSBUS[4], SLAICEPS[4] ) - copy.gsub!( /�*((?:\d+)|(?:x[a-f0-9]+));/ ) {|m| + copy.gsub!( /�*((?:\d+)|(?:x[a-f0-9]+));/ ) { m=$1 #m='0' if m=='' m = "0#{m}" if m[0] == ?x @@ -380,7 +380,8 @@ module REXML # Unescapes all possible entities def Text::unnormalize( string, doctype=nil, filter=nil, illegal=nil ) - string.gsub( /\r\n?/, "\n" ).gsub( REFERENCE ) { |ref| + string.gsub( /\r\n?/, "\n" ).gsub( REFERENCE ) { + ref = $& if ref[1] == ?# if ref[2] == ?x [ref[3...-1].to_i(16)].pack('U*') diff --git a/lib/rss/parser.rb b/lib/rss/parser.rb index 438c63b4ca..0cba624bcb 100644 --- a/lib/rss/parser.rb +++ b/lib/rss/parser.rb @@ -199,9 +199,7 @@ module RSS name = (@@class_names[uri] || {})[tag_name] return name if name - tag_name = tag_name.gsub(/[_\-]([a-z]?)/) do - $1.upcase - end + tag_name.gsub!(/[_\-]([a-z]?)/){$1.upcase} tag_name[0, 1].upcase + tag_name[1..-1] end diff --git a/lib/uri/common.rb b/lib/uri/common.rb index cf7d147cc4..f0d68884de 100644 --- a/lib/uri/common.rb +++ b/lib/uri/common.rb @@ -285,7 +285,8 @@ module URI # perhaps unsafe is String object unsafe = Regexp.new("[#{Regexp.quote(unsafe)}]", false, 'N') end - str.gsub(unsafe) do |us| + str.gsub(unsafe) do + us = $& tmp = '' us.each_byte do |uc| tmp << sprintf('%%%02X', uc) diff --git a/lib/uri/generic.rb b/lib/uri/generic.rb index d907e0b4b2..57fe0e4515 100644 --- a/lib/uri/generic.rb +++ b/lib/uri/generic.rb @@ -1105,7 +1105,7 @@ module URI @@to_s = Kernel.instance_method(:to_s) def inspect - @@to_s.bind(self).call.sub!(/>\z/) {" URL:#{self}>"} + @@to_s.bind(self).call.sub!(/>\z/, " URL:#{self}>") end def coerce(oth) diff --git a/lib/webrick/httpresponse.rb b/lib/webrick/httpresponse.rb index b3f1abef88..5c580ffb68 100644 --- a/lib/webrick/httpresponse.rb +++ b/lib/webrick/httpresponse.rb @@ -169,7 +169,7 @@ module WEBrick if @http_version.major > 0 data = status_line() @header.each{|key, value| - tmp = key.gsub(/\bwww|^te$|\b\w/){|s| s.upcase } + tmp = key.gsub(/\bwww|^te$|\b\w/){ $&.upcase } data << "#{tmp}: #{value}" << CRLF } @cookies.each{|cookie| diff --git a/lib/webrick/httpservlet/filehandler.rb b/lib/webrick/httpservlet/filehandler.rb index ae30c436fe..c6f253e3b8 100644 --- a/lib/webrick/httpservlet/filehandler.rb +++ b/lib/webrick/httpservlet/filehandler.rb @@ -371,7 +371,7 @@ module WEBrick if name == ".." dname = "Parent Directory" elsif name.size > 25 - dname = name.sub(/^(.{23})(.*)/){ $1 + ".." } + dname = name.sub(/^(.{23})(?:.*)/, '\1..') else dname = name end diff --git a/lib/yaml/baseemitter.rb b/lib/yaml/baseemitter.rb index 1aef152749..a1992f498b 100644 --- a/lib/yaml/baseemitter.rb +++ b/lib/yaml/baseemitter.rb @@ -132,7 +132,7 @@ module YAML # Folding paragraphs within a column # def fold( value ) - value.gsub( /(^[ \t]+.*$)|(\S.{0,#{options(:BestWidth) - 1}})(?:[ \t]+|(\n+(?=[ \t]|\Z))|$)/ ) do |s| + value.gsub( /(^[ \t]+.*$)|(\S.{0,#{options(:BestWidth) - 1}})(?:[ \t]+|(\n+(?=[ \t]|\Z))|$)/ ) do $1 || $2 + ( $3 || "\n" ) end end diff --git a/lib/yaml/encoding.rb b/lib/yaml/encoding.rb index 37f5cfda64..57dc553606 100644 --- a/lib/yaml/encoding.rb +++ b/lib/yaml/encoding.rb @@ -10,8 +10,8 @@ module YAML def YAML.escape( value, skip = "" ) value.gsub( /\\/, "\\\\\\" ). gsub( /"/, "\\\"" ). - gsub( /([\x00-\x1f])/ ) do |x| - skip[x] || ESCAPES[ x.unpack("C")[0] ] + gsub( /([\x00-\x1f])/ ) do + skip[$&] || ESCAPES[ $&.unpack("C")[0] ] end end @@ -19,7 +19,7 @@ module YAML # Unescape the condenses escapes # def YAML.unescape( value ) - value.gsub( /\\(?:([nevfbart\\])|0?x([0-9a-fA-F]{2})|u([0-9a-fA-F]{4}))/ ) { |x| + value.gsub( /\\(?:([nevfbart\\])|0?x([0-9a-fA-F]{2})|u([0-9a-fA-F]{4}))/ ) { if $3 ["#$3".hex ].pack('U*') elsif $2 |