More yield break surprises? - Re: Enumerable#inject is surprising me

dblack wrote:

Commit the fix, please.

Using the new version:

$ ./ruby -v
ruby 1.8.0 (2003-10-06) [i686-linux]
$ ./ruby -e ‘p [“a”].inject(“start”) {|x,y| “b”}’
“b”
$ ./ruby -e ‘p [“a”].inject(“start”) {|x,y| break “b”}’
“start”

I’m still not understanding why these should be different, or how
“start” gets into the first one (the first block) at all.

Hm,

maybe the fix introduced the following behavior ?
(ruby -v == 1.8.0 (2003-10-08) [i386-mswin32])

···

module Enumerable
def test_break
while true
while true
each {|x| yield x }
end
end
puts “not reached”
ensure
puts “reached”
end
end

(1…5).test_break { break “bla” }

results in

reached

/Christoph