ささだです.

 最近 ruby -w で動かすと使われて無さそうな変数に対して "assigned but
unused variable" と警告してくれるようです.

 で,いつも -w 付きで動かしている私ですが,標準ライブラリでもいくつかこ
の警告が出ているようです.対処頂くといいと思うのですが,どうでしょうか.

# 個人的には,benchmark とかよく使うので,鬱陶しい.


 参考までに,ruby 1.9.3dev (2010-07-19 trunk 28681) [i386-mswin32_90]
で以下のスクリプトを実行してみました.

$:.each{|dir|
  (Dir.glob(File.join(dir, '*.rb')) + Dir.glob(File.join(dir,
'net/*.rb'))).each{|rb|
    next if File.basename(rb) == 'debug.rb'
    puts rb
    begin
      require rb
    rescue Exception => e
      puts "Error: #{e}"
    end
  }
}

ruby 1.9.3dev (2010-07-19 trunk 28681) [i386-mswin32_90]
c:/ruby/trunk/lib/ruby/1.9.1/benchmark.rb:561: warning: assigned but
unused variable - i
c:/ruby/trunk/lib/ruby/1.9.1/benchmark.rb:561: warning: assigned but
unused variable - a
c:/ruby/trunk/lib/ruby/1.9.1/benchmark.rb:562: warning: assigned but
unused variable - a
c:/ruby/trunk/lib/ruby/1.9.1/benchmark.rb:563: warning: assigned but
unused variable - a
c:/ruby/trunk/lib/ruby/1.9.1/benchmark.rb:568: warning: assigned but
unused variable - i
c:/ruby/trunk/lib/ruby/1.9.1/benchmark.rb:568: warning: assigned but
unused variable - a
c:/ruby/trunk/lib/ruby/1.9.1/benchmark.rb:569: warning: assigned but
unused variable - a
c:/ruby/trunk/lib/ruby/1.9.1/benchmark.rb:570: warning: assigned but
unused variable - a
lib/complex.rb is deprecated
c:/ruby/trunk/lib/ruby/1.9.1/digest.rb:14: warning: assigned but unused
variable - e
c:/ruby/trunk/lib/ruby/1.9.1/rubygems.rb:1062: warning: method
redefined; discarding old gem
<internal:gem_prelude>:15: warning: previous definition of gem was here
c:/ruby/trunk/lib/ruby/1.9.1/rubygems/source_index.rb:360: warning:
assigned but unused variable - name
c:/ruby/trunk/lib/ruby/1.9.1/rubygems/specification.rb:674: warning:
assigned but unused variable - default_value
c:/ruby/trunk/lib/ruby/1.9.1/rubygems/specification.rb:706: warning:
assigned but unused variable - yaml
c:/ruby/trunk/lib/ruby/1.9.1/rubygems/custom_require.rb:7: warning:
loading in progress, circular require considered harmful -
c:/ruby/trunk/lib/ruby/1.9.1/rubygems.rb
	from t.rb:1:in `<main>'
	from t.rb:1:in `each'
	from t.rb:2:in `block in <main>'
	from t.rb:2:in `each'
	from t.rb:6:in `block (2 levels) in <main>'
	from t.rb:6:in `require'
	from c:/ruby/trunk/lib/ruby/1.9.1/gauntlet_rubygems.rb:1:in `<top
(required)>'
	from c:/ruby/trunk/lib/ruby/1.9.1/gauntlet_rubygems.rb:1:in `require'
	from c:/ruby/trunk/lib/ruby/1.9.1/rubygems.rb:1119:in `<top (required)>'
	from c:/ruby/trunk/lib/ruby/1.9.1/rubygems.rb:1119:in `require'
	from c:/ruby/trunk/lib/ruby/1.9.1/rubygems/custom_require.rb:7:in `<top
(required)>'
	from c:/ruby/trunk/lib/ruby/1.9.1/rubygems/custom_require.rb:7:in `require'
c:/ruby/trunk/lib/ruby/1.9.1/abbrev.rb
c:/ruby/trunk/lib/ruby/1.9.1/base64.rb
c:/ruby/trunk/lib/ruby/1.9.1/benchmark.rb
c:/ruby/trunk/lib/ruby/1.9.1/cgi.rb
c:/ruby/trunk/lib/ruby/1.9.1/cmath.rb
c:/ruby/trunk/lib/ruby/1.9.1/complex.rb
c:/ruby/trunk/lib/ruby/1.9.1/csv.rb
c:/ruby/trunk/lib/ruby/1.9.1/date.rb
c:/ruby/trunk/lib/ruby/1.9.1/delegate.rb
c:/ruby/trunk/lib/ruby/1.9.1/digest.rb
c:/ruby/trunk/lib/ruby/1.9.1/dl.rb
c:/ruby/trunk/lib/ruby/1.9.1/drb.rb
c:/ruby/trunk/lib/ruby/1.9.1/e2mmap.rb
c:/ruby/trunk/lib/ruby/1.9.1/English.rb
c:/ruby/trunk/lib/ruby/1.9.1/erb.rb
c:/ruby/trunk/lib/ruby/1.9.1/fileutils.rb
c:/ruby/trunk/lib/ruby/1.9.1/find.rb
c:/ruby/trunk/lib/ruby/1.9.1/forwardable.rb
c:/ruby/trunk/lib/ruby/1.9.1/gauntlet_rubygems.rb
Error: cannot load such file -- gauntlet
c:/ruby/trunk/lib/ruby/1.9.1/getoptlong.rb
c:/ruby/trunk/lib/ruby/1.9.1/gserver.rb
c:/ruby/trunk/lib/ruby/1.9.1/ipaddr.rb
c:/ruby/trunk/lib/ruby/1.9.1/irb.rb
c:/ruby/trunk/lib/ruby/1.9.1/json.rb
Error: cannot load such file -- iconv
c:/ruby/trunk/lib/ruby/1.9.1/kconv.rb
c:/ruby/trunk/lib/ruby/1.9.1/kconv.rb:205: warning: assigned but unused
variable - form_enc
c:/ruby/trunk/lib/ruby/1.9.1/i386-mswin32_90/nkf.so: warning: failed to
load encoding (UTF-32BE); use ASCII-8BIT instead
c:/ruby/trunk/lib/ruby/1.9.1/logger.rb
c:/ruby/trunk/lib/ruby/1.9.1/mathn.rb
c:/ruby/trunk/lib/ruby/1.9.1/matrix.rb
c:/ruby/trunk/lib/ruby/1.9.1/mkmf.rb
c:/ruby/trunk/lib/ruby/1.9.1/monitor.rb
c:/ruby/trunk/lib/ruby/1.9.1/mutex_m.rb
c:/ruby/trunk/lib/ruby/1.9.1/observer.rb
c:/ruby/trunk/lib/ruby/1.9.1/open-uri.rb
c:/ruby/trunk/lib/ruby/1.9.1/open-uri.rb:129: warning: assigned but
unused variable - perm
c:/ruby/trunk/lib/ruby/1.9.1/open-uri.rb:483: warning: assigned but
unused variable - parameters
c:/ruby/trunk/lib/ruby/1.9.1/open-uri.rb:715: warning: assigned but
unused variable - v
c:/ruby/trunk/lib/ruby/1.9.1/uri/common.rb:352: warning: assigned but
unused variable - uri_ref
c:/ruby/trunk/lib/ruby/1.9.1/open3.rb
c:/ruby/trunk/lib/ruby/1.9.1/optparse.rb
c:/ruby/trunk/lib/ruby/1.9.1/optparse.rb:1075: warning: assigned but
unused variable - n
c:/ruby/trunk/lib/ruby/1.9.1/ostruct.rb
c:/ruby/trunk/lib/ruby/1.9.1/pathname.rb
c:/ruby/trunk/lib/ruby/1.9.1/pp.rb
c:/ruby/trunk/lib/ruby/1.9.1/prettyprint.rb
c:/ruby/trunk/lib/ruby/1.9.1/prime.rb
c:/ruby/trunk/lib/ruby/1.9.1/profile.rb
c:/ruby/trunk/lib/ruby/1.9.1/profiler.rb
c:/ruby/trunk/lib/ruby/1.9.1/pstore.rb
c:/ruby/trunk/lib/ruby/1.9.1/rake.rb
c:/ruby/trunk/lib/ruby/1.9.1/rake.rb:1041: warning: assigned but unused
variable - ex
c:/ruby/trunk/lib/ruby/1.9.1/rake.rb:1690: warning: assigned but unused
variable - arg_names
c:/ruby/trunk/lib/ruby/1.9.1/rake.rb:1798: warning: assigned but unused
variable - md
c:/ruby/trunk/lib/ruby/1.9.1/rake.rb:2248: warning: assigned but unused
variable - ex2
c:/ruby/trunk/lib/ruby/1.9.1/rational.rb
lib/rational.rb is deprecated
c:/ruby/trunk/lib/ruby/1.9.1/rdoc.rb
c:/ruby/trunk/lib/ruby/1.9.1/resolv-replace.rb
c:/ruby/trunk/lib/ruby/1.9.1/resolv-replace.rb:54: warning: assigned but
unused variable - err
c:/ruby/trunk/lib/ruby/1.9.1/dl/import.rb:99: warning: assigned but
unused variable - prekey
c:/ruby/trunk/lib/ruby/1.9.1/dl/struct.rb:101: warning: assigned but
unused variable - size
c:/ruby/trunk/lib/ruby/1.9.1/win32/resolv.rb:76: warning: character
class has duplicated range: /^[\w\d]+\./
c:/ruby/trunk/lib/ruby/1.9.1/resolv.rb
c:/ruby/trunk/lib/ruby/1.9.1/ripper.rb
c:/ruby/trunk/lib/ruby/1.9.1/rss.rb
c:/ruby/trunk/lib/ruby/1.9.1/rss/rss.rb:1098: warning: assigned but
unused variable - model_uri
c:/ruby/trunk/lib/ruby/1.9.1/rss/rss.rb:1098: warning: assigned but
unused variable - getter
c:/ruby/trunk/lib/ruby/1.9.1/rss/rss.rb:1096: warning: assigned but
unused variable - _tags
c:/ruby/trunk/lib/ruby/1.9.1/rexml/element.rb:877: warning: assigned but
unused variable - rv
c:/ruby/trunk/lib/ruby/1.9.1/rexml/element.rb:1095: warning: assigned
but unused variable - element_document
c:/ruby/trunk/lib/ruby/1.9.1/rexml/element.rb:1200: warning: assigned
but unused variable - res
c:/ruby/trunk/lib/ruby/1.9.1/rexml/child.rb:91: warning: assigned but
unused variable - encoding
c:/ruby/trunk/lib/ruby/1.9.1/rexml/attribute.rb:118: warning: assigned
but unused variable - doctype
c:/ruby/trunk/lib/ruby/1.9.1/rexml/doctype.rb:118: warning: assigned but
unused variable - next_indent
c:/ruby/trunk/lib/ruby/1.9.1/rexml/doctype.rb:255: warning: `+' after
local variable is interpreted as binary operator
c:/ruby/trunk/lib/ruby/1.9.1/rexml/doctype.rb:255: warning: even though
it seems like unary operator
c:/ruby/trunk/lib/ruby/1.9.1/rexml/functions.rb:173: warning: assigned
but unused variable - test_string
c:/ruby/trunk/lib/ruby/1.9.1/rexml/xpath_parser.rb:689: warning:
assigned but unused variable - enum
c:/ruby/trunk/lib/ruby/1.9.1/rexml/parsers/xpathparser.rb:285: warning:
assigned but unused variable - res
c:/ruby/trunk/lib/ruby/1.9.1/rexml/parsers/xpathparser.rb:581: warning:
assigned but unused variable - arry
c:/ruby/trunk/lib/ruby/1.9.1/rss/atom.rb:530: warning: assigned but
unused variable - subtype
c:/ruby/trunk/lib/ruby/1.9.1/rss/maker/1.0.rb:35: warning: assigned but
unused variable - set
c:/ruby/trunk/lib/ruby/1.9.1/rss/maker/0.9.rb:27: warning: assigned but
unused variable - set
c:/ruby/trunk/lib/ruby/1.9.1/rss/maker/0.9.rb:260: warning: assigned but
unused variable - set
c:/ruby/trunk/lib/ruby/1.9.1/rss/maker/dublincore.rb:17: warning:
assigned but unused variable - full_klass_name
c:/ruby/trunk/lib/ruby/1.9.1/rubygems.rb
c:/ruby/trunk/lib/ruby/1.9.1/scanf.rb
c:/ruby/trunk/lib/ruby/1.9.1/securerandom.rb
c:/ruby/trunk/lib/ruby/1.9.1/set.rb
c:/ruby/trunk/lib/ruby/1.9.1/shell.rb
c:/ruby/trunk/lib/ruby/1.9.1/shell/system-command.rb:87: warning:
assigned but unused variable - th
c:/ruby/trunk/lib/ruby/1.9.1/shell/system-command.rb:112: warning:
assigned but unused variable - th
c:/ruby/trunk/lib/ruby/1.9.1/sync.rb:131: warning: assigned but unused
variable - ret
(eval):7: warning: method redefined; discarding old included
(eval):7: warning: previous definition of included was here
c:/ruby/trunk/lib/ruby/1.9.1/shell.rb:49: warning: method redefined;
discarding old debug=
c:/ruby/trunk/lib/ruby/1.9.1/shell.rb:115: warning: method redefined;
discarding old debug=
c:/ruby/trunk/lib/ruby/1.9.1/shellwords.rb
c:/ruby/trunk/lib/ruby/1.9.1/singleton.rb
c:/ruby/trunk/lib/ruby/1.9.1/socket.rb
c:/ruby/trunk/lib/ruby/1.9.1/syck.rb
c:/ruby/trunk/lib/ruby/1.9.1/sync.rb
c:/ruby/trunk/lib/ruby/1.9.1/tempfile.rb
c:/ruby/trunk/lib/ruby/1.9.1/thread.rb
c:/ruby/trunk/lib/ruby/1.9.1/thwait.rb
c:/ruby/trunk/lib/ruby/1.9.1/time.rb
c:/ruby/trunk/lib/ruby/1.9.1/timeout.rb
c:/ruby/trunk/lib/ruby/1.9.1/tmpdir.rb
c:/ruby/trunk/lib/ruby/1.9.1/tracer.rb
c:/ruby/trunk/lib/ruby/1.9.1/tsort.rb
c:/ruby/trunk/lib/ruby/1.9.1/ubygems.rb
c:/ruby/trunk/lib/ruby/1.9.1/un.rb
c:/ruby/trunk/lib/ruby/1.9.1/uri.rb
c:/ruby/trunk/lib/ruby/1.9.1/weakref.rb
c:/ruby/trunk/lib/ruby/1.9.1/webrick.rb
c:/ruby/trunk/lib/ruby/1.9.1/webrick/log.rb:63: warning: assigned but
unused variable - str
c:/ruby/trunk/lib/ruby/1.9.1/webrick/httpresponse.rb:283: warning:
assigned but unused variable - remain
c:/ruby/trunk/lib/ruby/1.9.1/webrick/httpservlet/erbhandler.rb:47:
warning: assigned but unused variable - meta_vars
c:/ruby/trunk/lib/ruby/1.9.1/webrick/httpservlet/erbhandler.rb:48:
warning: assigned but unused variable - query
c:/ruby/trunk/lib/ruby/1.9.1/Win32API.rb
Warning:c:/ruby/trunk/lib/ruby/1.9.1/rubygems/custom_require.rb:31:
Win32API is deprecated after Ruby 1.9.1; use dl directly instead
c:/ruby/trunk/lib/ruby/1.9.1/win32ole.rb
c:/ruby/trunk/lib/ruby/1.9.1/yaml.rb
c:/ruby/trunk/lib/ruby/1.9.1/net/ftp.rb
c:/ruby/trunk/lib/ruby/1.9.1/net/ftp.rb:325: warning: assigned but
unused variable - resp
c:/ruby/trunk/lib/ruby/1.9.1/net/http.rb
c:/ruby/trunk/lib/ruby/1.9.1/net/http.rb:1566: warning: assigned but
unused variable - main
c:/ruby/trunk/lib/ruby/1.9.1/net/https.rb
Error: cannot load such file -- openssl
c:/ruby/trunk/lib/ruby/1.9.1/net/imap.rb
c:/ruby/trunk/lib/ruby/1.9.1/net/imap.rb:2683: warning: assigned but
unused variable - mailbox
c:/ruby/trunk/lib/ruby/1.9.1/net/pop.rb
c:/ruby/trunk/lib/ruby/1.9.1/net/protocol.rb
c:/ruby/trunk/lib/ruby/1.9.1/net/smtp.rb
c:/ruby/trunk/lib/ruby/1.9.1/net/telnet.rb
c:/ruby/trunk/lib/ruby/1.9.1/i386-mswin32_90/rbconfig.rb

-- 
// SASADA Koichi at atdot dot net