From: Tanaka Akira Date: 2009-05-09T02:10:21+09:00 Subject: [ruby-dev:38390] [Bug:1.8] Tempfile and extended Enumerable 1.8.8dev で、以下のように、Enumerable に each2 を定義し、 Tempfile を each2 で繰り返そうとすると、ブロックが呼ばれませ ん。 % cat tst.rb require 'tempfile' module Enumerable def each2(&block) each(&block) end end t = Tempfile.new("foo") t.puts "a", "b", "c" t.rewind t.each2 {|x| p x } % ./ruby -v tst.rb ruby 1.8.8dev (2009-05-08 revision 23366) [i686-linux] (なにも出てこない) each2 でなく、each を使えば呼ばれます。 % ./ruby -rtempfile -ve ' t = Tempfile.new("foo") t.puts "a", "b", "c" t.rewind t.each {|x| p x } ' ruby 1.8.8dev (2009-05-08 revision 23366) [i686-linux] "a\n" "b\n" "c\n" また、1.9 では each2 でも呼ばれます。 % ruby -v tst.rb ruby 1.9.2dev (2009-05-08 trunk 23370) [i686-linux] "a\n" "b\n" "c\n" そして、1.8.1 でも呼ばれます。 % ruby-1.8.1 -v tst.rb ruby 1.8.1 (2003-12-25) [i686-linux] "a\n" "b\n" "c\n" なお、1.8.6p368 では LocalJumpError になります。 % ruby-1.8.6p368 -v tst.rb ruby 1.8.6 (2009-03-31 patchlevel 368) [i686-linux] tst.rb:4:in `each': no block given (LocalJumpError) from tst.rb:4:in `each2' from /home/ruby/186p368/lib/ruby/1.8/delegate.rb:272:in `__send__' from /home/ruby/186p368/lib/ruby/1.8/delegate.rb:272:in `method_missing' from tst.rb:10 -- [田中 哲][たなか あきら][Tanaka Akira]