From: Nobuhiro IMAI Date: 2009-10-06T22:04:03+09:00 Subject: [ruby-dev:39440] Re: [Bug #2179] 1.9.2において block のスコープがおかしいときがある いまいです。 From: 益隆 三村 Date: Tue, 6 Oct 2009 21:14:10 +0900 > rubyspecを流しているときに気づいたのですが、 > ruby1.9.2 の trunk(rev 25243) にて blockのスコープが正しく動いてないように見えます。 > # 対応するrubyspecは core/string/upto_spec.rb:21 > % ruby -v > ruby 1.9.1p243 (2009-07-16 revision 24175) [i386-darwin9.8.0] > % irb > ruby-1.9.1-p243 > a=[]; "25".upto("5"){|s|a< => ["25"] > > % ruby -v > ruby 1.9.2dev (2009-10-06 trunk 25243) [i386-darwin9.8.0] > % irb > ruby-1.9.2-head > a=[]; "25".upto("5"){|s|a< => [] これはブロックが一度も評価されてないからですね。 $ ruby1.9.1 -ve '"25".upto("5"){raise}' ruby 1.9.1p243 (2009-07-16 revision 24175) [i486-linux] -e:1:in `block in
': unhandled exception from -e:1:in `upto' from -e:1:in `
' $ ruby1.9 -ve '"25".upto("5"){raise}' ruby 1.9.2dev (2009-10-03 trunk 25201) [i686-linux] 両端が数値とみなせるときの String#upto の挙動の変更によるものだと思い ます。これは書いておいた方がよいと思うので、パッチを書いてみました。 -- Nobuhiro IMAI Key fingerprint = F39E D552 545D 7C64 D690 F644 5A15 746C BD8E 7106 Index: string.c =================================================================== --- string.c (revision 25243) +++ string.c (working copy) @@ -2863,6 +2863,14 @@ * * a8 a9 b0 b1 b2 b3 b4 b5 b6 * a8 a9 b0 b1 b2 b3 b4 b5 b6 + * + * If str and other_str contains only ascii numeric characters, + * both are recognized as decimal numbers. In addition, the width of + * string (e.g. leading zeros) is handled appropriately. + * + * "9".upto("11").to_a => ["9", "10", "11"] + * "25".upto("5").to_a => [] + * "07".upto("11").to_a => ["07", "08", "09", "10", "11"] */ static VALUE