From: Takeshi Komiya Date: 2003-10-14T15:57:52+09:00 Subject: [ruby-list:38551] optparse.rb の互換性 小宮@神奈川工科大学です。 ruby1.6 から ruby1.8 に乗り換えた際に rdtool に --with-part オプションが無視されてしまうようになってしまいました。 % cat test.rd =begin html hello world. =end % rd2 --with-part=html test.rd Error: file empty. 何が原因なのかコードを追いかけてみたところ、optparse.rb の 挙動が 1.6 と 1.8 で異なっていることが原因のようです。 RAA から optparse-0.12 を拾ってきて % cat test.rb ARGV.options do |q| q.on("--with-part=PART", /(\w+)(?:\s*:\s*(\w+))?/) do |src, part, filter| p src, part, filter end end ARGV.parse! というコードを実行したところ、 % ruby1.6 -v -r optparse-0.12/optparse.rb test.rb --with-part=html ruby 1.6.8 (2003-07-09) [i386-linux] "html" "html" nil % ruby1.8 -v -W0 -r optparse-0.12/optparse.rb test.rb --with-part=html ruby 1.8.0 (2003-10-05) [i386-linux] ["html", "html", nil] nil nil という結果が返ってきました。 (ruby1.8 のケースでは warning が出るため、-W0 を付けています) ruby1.8 に添付の optparse.rb でも optparse-0.12 と同じ動きをします。 % ruby1.8 -v -r optparse.rb -e 'p OptionParser.new.version' ruby 1.8.0 (2003-10-05) [i386-linux] /usr/lib/ruby/1.8/optparse.rb:789: warning: instance variable @version not initialized "1.8.0" % ruby1.8 -r optparse.rb test.rb --with-part=html ["html", "html", nil] nil nil これは optparse.rb の仕様が変更された、と言うことなのでしょうか? --- 小宮 健