[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Enumerable#inject is surprising me...

dblack

10/9/2003 1:35:00 AM

1 Answer

Christoph

10/9/2003 7:26:00 AM

0

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