From 88d6c083ea969b5e7b24315fd612958755afcc54 Mon Sep 17 00:00:00 2001 From: nobu Date: Mon, 9 Oct 2006 14:41:24 +0000 Subject: * ext/extmk.rb, lib/fileutils.rb, lib/mkmf.rb, lib/optparse.rb, lib/shellwords.rb: get rid of shadowing outer local variable. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11112 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/fileutils.rb | 6 +++--- lib/mkmf.rb | 29 +++++++++++++++-------------- lib/optparse.rb | 31 ++++++++++++++----------------- lib/shellwords.rb | 1 - 4 files changed, 32 insertions(+), 35 deletions(-) (limited to 'lib') diff --git a/lib/fileutils.rb b/lib/fileutils.rb index c80a69e554..976b838838 100644 --- a/lib/fileutils.rb +++ b/lib/fileutils.rb @@ -212,11 +212,11 @@ module FileUtils stack.push path path = File.dirname(path) end - stack.reverse_each do |path| + stack.reverse_each do |dir| begin - fu_mkdir path, options[:mode] + fu_mkdir dir, options[:mode] rescue SystemCallError => err - raise unless File.directory?(path) + raise unless File.directory?(dir) end end end diff --git a/lib/mkmf.rb b/lib/mkmf.rb index a64729576c..5dad67975e 100644 --- a/lib/mkmf.rb +++ b/lib/mkmf.rb @@ -108,7 +108,7 @@ end def map_dir(dir, map = nil) map ||= INSTALL_DIRS - map.inject(dir) {|dir, (orig, new)| dir.gsub(orig, new)} + map.inject(dir) {|d, (orig, new)| d.gsub(orig, new)} end topdir = File.dirname(libdir = File.dirname(__FILE__)) @@ -501,7 +501,8 @@ def install_files(mfile, ifiles, map = nil, srcprefix = nil) len = srcdir.size end f = nil - Dir.glob(files) do |f| + Dir.glob(files) do |fx| + f = fx f[0..len] = "" if len d = File.dirname(f) d.sub!(prefix, "") if prefix @@ -967,11 +968,11 @@ def dir_config(target, idefault=nil, ldefault=nil) idirs = idir ? Array === idir ? idir : idir.split(File::PATH_SEPARATOR) : [] if defaults - idirs.concat(defaults.collect {|dir| dir + "/include"}) + idirs.concat(defaults.collect {|d| d + "/include"}) idir = ([idir] + idirs).compact.join(File::PATH_SEPARATOR) end unless idirs.empty? - idirs.collect! {|dir| "-I" + dir} + idirs.collect! {|d| "-I" + d} idirs -= Shellwords.shellwords($CPPFLAGS) unless idirs.empty? $CPPFLAGS = (idirs.quote << $CPPFLAGS).join(" ") @@ -980,7 +981,7 @@ def dir_config(target, idefault=nil, ldefault=nil) ldirs = ldir ? Array === ldir ? ldir : ldir.split(File::PATH_SEPARATOR) : [] if defaults - ldirs.concat(defaults.collect {|dir| dir + "/lib"}) + ldirs.concat(defaults.collect {|d| d + "/lib"}) ldir = ([ldir] + ldirs).compact.join(File::PATH_SEPARATOR) end $LIBPATH = ldirs | $LIBPATH @@ -1177,7 +1178,7 @@ def create_makefile(target, srcprefix = nil) $objs.push(obj) unless $objs.index(obj) end elsif !(srcs = $srcs) - srcs = $objs.collect {|obj| obj.sub(/\.o\z/, '.c')} + srcs = $objs.collect {|o| o.sub(/\.o\z/, '.c')} end $srcs = srcs for i in $objs @@ -1282,7 +1283,7 @@ static: $(STATIC_LIB)#{$extout ? " install-rb" : ""} dirs << dir mfile.print "pre-install-rb#{sfx}: #{dir}\n" end - files.each do |f| + for f in files dest = "#{dir}/#{File.basename(f)}" mfile.print("install-rb#{sfx}: #{dest}\n") mfile.print("#{dest}: #{f}\n\t$(#{$extout ? 'COPY' : 'INSTALL_DATA'}) ") @@ -1303,7 +1304,7 @@ static: $(STATIC_LIB)#{$extout ? " install-rb" : ""} end end dirs.unshift(sodir) if target and !dirs.include?(sodir) - dirs.each {|dir| mfile.print "#{dir}:\n\t$(MAKEDIRS) $@\n"} + dirs.each {|d| mfile.print "#{d}:\n\t$(MAKEDIRS) $@\n"} mfile.print <<-SITEINSTALL @@ -1379,7 +1380,7 @@ site-install-rb: install-rb implicit = [[m[1], m[2]], [m.post_match]] next elsif RULE_SUBST and /\A(?!\s*\w+\s*=)[$\w][^#]*:/ =~ line - line.gsub!(%r"(?<=\s)(?!\.)([^$(){}+=:\s\/\\,]+)(?=\s|\z)") {|*m| RULE_SUBST % m} + line.gsub!(%r"(?<=\s)(?!\.)([^$(){}+=:\s\/\\,]+)(?=\s|\z)", &RULE_SUBST.method(:%)) end depout << line end @@ -1408,7 +1409,7 @@ site-install-rb: install-rb else headers = %w[ruby.h defines.h] if RULE_SUBST - headers.each {|h| h.sub!(/.*/) {|*m| RULE_SUBST % m}} + headers.each {|h| h.sub!(/.*/, &RULE_SUBST.method(:%))} end headers << $config_h if $config_h headers << "$(RUBY_EXTCONF_H)" if $extconf_h @@ -1508,13 +1509,13 @@ EXPORT_PREFIX = config_string('EXPORT_PREFIX') {|s| s.strip} hdr = [] config_string('COMMON_MACROS') do |s| - Shellwords.shellwords(s).each do |s| - /(.*?)(?:=(.*))/ =~ s + Shellwords.shellwords(s).each do |w| + /(.*?)(?:=(.*))/ =~ w hdr << "#define #$1 #$2" end end config_string('COMMON_HEADERS') do |s| - Shellwords.shellwords(s).each {|s| hdr << "#include <#{s}>"} + Shellwords.shellwords(s).each {|w| hdr << "#include <#{w}>"} end COMMON_HEADERS = hdr.join("\n") COMMON_LIBS = config_string('COMMON_LIBS', &split) || [] @@ -1537,7 +1538,7 @@ LIBPATHFLAG = config_string('LIBPATHFLAG') || ' -L"%s"' RPATHFLAG = config_string('RPATHFLAG') || '' LIBARG = config_string('LIBARG') || '-l%s' -sep = config_string('BUILD_FILE_SEPARATOR') {|sep| ":/=#{sep}" if sep != "/"} || "" +sep = config_string('BUILD_FILE_SEPARATOR') {|s| ":/=#{s}" if sep != "/"} || "" CLEANINGS = " clean: @-$(RM) $(CLEANLIBS#{sep}) $(CLEANOBJS#{sep}) $(CLEANFILES#{sep}) diff --git a/lib/optparse.rb b/lib/optparse.rb index 2c034043e0..c4e9ad65d4 100644 --- a/lib/optparse.rb +++ b/lib/optparse.rb @@ -221,7 +221,7 @@ class OptionParser def complete(key, icase = false, pat = nil) pat ||= Regexp.new('\A' + Regexp.quote(key).gsub(/\w+\b/, '\&\w*'), icase) - canon, sw, k, v, cn = nil + canon, sw, cn = nil candidates = [] each do |k, *v| (if Regexp === k @@ -349,7 +349,7 @@ class OptionParser if conv val = conv.call(*val) else - val = proc {|val| val}.call(*val) + val = proc {|v| v}.call(*val) end return arg, block, val end @@ -368,7 +368,7 @@ class OptionParser # +indent+:: Prefix string indents all summarized lines. # def summarize(sdone = [], ldone = [], width = 1, max = width - 1, indent = "") - sopts, lopts, s = [], [], nil + sopts, lopts = [], [], nil @short.each {|s| sdone.fetch(s) {sopts << s}; sdone[s] = true} if @short @long.each {|s| ldone.fetch(s) {lopts << s}; ldone[s] = true} if @long return if sopts.empty? and lopts.empty? # completely hidden @@ -384,9 +384,9 @@ class OptionParser end left[0] << arg if arg - mlen = left.collect {|s| s.length}.max.to_i + mlen = left.collect {|ss| ss.length}.max.to_i while mlen > width and l = left.shift - mlen = left.collect {|s| s.length}.max.to_i if l.length == mlen + mlen = left.collect {|ss| ss.length}.max.to_i if l.length == mlen yield(indent + l) end @@ -453,7 +453,7 @@ class OptionParser raise MissingArgument if argv.empty? arg = argv.shift end - conv_arg(*parse_arg(arg) {|*exc| raise(*exc)}) + conv_arg(*parse_arg(arg, &method(:raise))) end end @@ -557,7 +557,6 @@ class OptionParser # +nlopts+:: Negated long style options list. # def update(sw, sopts, lopts, nsw = nil, nlopts = nil) - o = nil sopts.each {|o| @short[o] = sw} if sopts lopts.each {|o| @long[o] = sw} if lopts nlopts.each {|o| @long[o] = nsw} if nsw and nlopts @@ -1063,7 +1062,6 @@ class OptionParser default_style = Switch::NoArgument default_pattern = nil klass = nil - o = nil n, q, a = nil opts.each do |o| @@ -1097,7 +1095,7 @@ class OptionParser else raise ArgumentError, "argument pattern given twice" end - o.each {|(o, *v)| pattern[o] = v.fetch(0) {o}} + o.each {|pat, *v| pattern[pat] = v.fetch(0) {pat}} when Module raise ArgumentError, "unsupported argument type: #{o}" when *ArgumentStyle.keys @@ -1246,8 +1244,8 @@ class OptionParser # :nodoc: def parse_in_order(argv = default_argv, setter = nil, &nonopt) - opt, arg, sw, val, rest = nil - nonopt ||= proc {|arg| throw :terminate, arg} + opt, arg, val, rest = nil + nonopt ||= proc {|a| throw :terminate, a} argv.unshift(arg) if arg = catch(:terminate) { while arg = argv.shift case arg @@ -1301,7 +1299,8 @@ class OptionParser # non-option argument else catch(:prune) do - visit(:each_option) do |sw| + visit(:each_option) do |sw0| + sw = sw0 sw.block.call(arg) if Switch === sw and sw.match_nonswitch?(arg) end nonopt.call(arg) @@ -1332,8 +1331,7 @@ class OptionParser # def permute!(argv = default_argv) nonopts = [] - arg = nil - order!(argv) {|arg| nonopts << arg} + order!(argv, &nonopts.method(:<<)) argv[0, 0] = nonopts argv end @@ -1410,7 +1408,6 @@ class OptionParser # +block+. # def visit(id, *args, &block) - el = nil @stack.reverse_each do |el| el.send(id, *args, &block) end @@ -1443,7 +1440,7 @@ class OptionParser search(typ, opt) {|sw| return [sw, opt]} # exact match or... end raise AmbiguousOption, catch(:ambiguous) { - visit(:complete, typ, opt, icase, *pat) {|opt, *sw| return sw} + visit(:complete, typ, opt, icase, *pat) {|o, *sw| return sw} raise InvalidOption, opt } end @@ -1562,7 +1559,7 @@ class OptionParser # accept(Array) do |s,| if s - s = s.split(',').collect {|s| s unless s.empty?} + s = s.split(',').collect {|ss| ss unless ss.empty?} end s end diff --git a/lib/shellwords.rb b/lib/shellwords.rb index 1d97cd62f2..04d0c4fff8 100644 --- a/lib/shellwords.rb +++ b/lib/shellwords.rb @@ -28,7 +28,6 @@ module Shellwords def shellwords(line) words = [] field = '' - word = sq = dq = esc = garbage = sep = nil line.scan(/\G\s*(?>([^\s\\\'\"]+)|'([^\']*)'|"((?:[^\"\\]|\\.)*)"|(\\.?)|(\S))(\s|\z)?/m) do |word, sq, dq, esc, garbage, sep| raise ArgumentError, "Unmatched double quote: #{line.inspect}" if garbage -- cgit v1.2.3