[Bug:1.8] Tempfile and extended Enumerable


#1

1.8.8dev e$B$G!"0J2<$N$h$&$K!"e(BEnumerable e$B$Ke(B each2
e$B$rDj5A$7!“e(B
Tempfile e$B$re(B each2 e$B$G7+$jJV$=$&$H$9$k$H!”%V%m%C%/$,8F$P$l$^$;e(B
e$B$s!#e(B

% 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]
(e$B$J$K$b=P$F$3$J$$e(B)

each2 e$B$G$J$/!"e(Beach e$B$r;H$($P8F$P$l$^$9!#e(B

% ./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”

e$B$^$?!"e(B1.9 e$B$G$Oe(B each2 e$B$G$b8F$P$l$^$9!#e(B

% ruby -v tst.rb
ruby 1.9.2dev (2009-05-08 trunk 23370) [i686-linux]
“a\n”
“b\n”
“c\n”

e$B$=$7$F!"e(B1.8.1 e$B$G$b8F$P$l$^$9!#e(B

% ruby-1.8.1 -v tst.rb
ruby 1.8.1 (2003-12-25) [i686-linux]
“a\n”
“b\n”
“c\n”

e$B$J$*!"e(B1.8.6p368 e$B$G$Oe(B LocalJumpError e$B$K$J$j$^$9!#e(B

% 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:ineach2’
from /home/ruby/186p368/lib/ruby/1.8/delegate.rb:272:in
__send__' from /home/ruby/186p368/lib/ruby/1.8/delegate.rb:272:inmethod_missing’
from tst.rb:10


#2

At Sat, 9 May 2009 02:10:21 +0900,
Tanaka A. wrote:

1.8.8dev で、以下のように、Enumerable に each2 を定義し、
Tempfile を each2 で繰り返そうとすると、ブロックが呼ばれませ
ん。

ã€€ãƒ–ãƒ­ãƒƒã‚¯ãŒæ¸¡ã•ã‚Œã¦ã„ãªã„ã®ãŒåŽŸå› ãªã®ã§ã€ã“ã†ã™ã‚Œã°ç›´ã‚Šã¾ã™ã€‚

Index: lib/delegate.rb

— lib/delegate.rb (revision 23370)
+++ lib/delegate.rb (working copy)
@@ -151,12 +151,12 @@ class Delegator
alias initialize_methods initialize

Handles the magic of delegation through __getobj__.

  • def method_missing(m, *args)
  • def method_missing(m, *args, &block)
    target = self.getobj
    unless target.respond_to?(m)
  •  super(m, *args)
    
  •  super(m, *args, &block)
    
    end
  • target.send(m, *args)
  • target.send(m, *args, &block)
    end

@@ -264,11 +264,11 @@ def DelegateClass(superclass)
def initialize(obj) # :nodoc:
@_dc_obj = obj
end

  • def method_missing(m, *args) # :nodoc:
  • def method_missing(m, *args, &block) # :nodoc:
    unless @_dc_obj.respond_to?(m)
  •    super(m, *args)
    
  •    super(m, *args, &block)
     end
    
  •  @_dc_obj.__send__(m, *args)
    
  •  @_dc_obj.__send__(m, *args, &block)
    
    end
    def respond_to?(m, include_private = false) # :nodoc:
    return true if super

 しかし、 trunk だけ手当てされたのはどういうわけでしょうね?


#3

e$B$^$D$b$He(B e$B$f$-$R$m!we(BEuruko09e$B$G$9e(B

In message “Re: [ruby-dev:38391] Re: [Bug:1.8] Tempfile and extended
Enumerable”
on Sat, 9 May 2009 04:06:30 +0900, “Akinori MUSHA”
removed_email_address@domain.invalid writes:

|Tanaka A. wrote:
|> 1.8.8dev e$B$G!"0J2<$N$h$&$K!“e(BEnumerable e$B$Ke(B each2 e$B$rDj5A$7!“e(B
|> Tempfile e$B$re(B each2 e$B$G7+$jJV$=$&$H$9$k$H!”%V%m%C%/$,8F$P$l$^$;e(B
|> e$B$s!#e(B
|
|e$B!!%V%m%C%/$,EO$5$l$F$$$J$$$N$,860x$J$N$G!”$3$&$9$l$PD>$j$^$9!#e(B

e$B%3%_%C%H$7$F$$$?$@$1$^$;$s$+!)e(B


#4

At Sat, 9 May 2009 21:05:00 +0900,
matz wrote:

コミットしていただけませんか?
 ruby_1_8 にコミットしました。ruby_1_8_7 および ruby_1_8_6 にも
適用できます。