From: dblack@... Date: 2003-10-09T20:24:37+09:00 Subject: Re: Enumerable#inject is surprising me... Hi -- On Thu, 9 Oct 2003, ts wrote: > >>>>> "d" == dblack writes: > > d> $ ./ruby -e 'p ["a"].inject("start") {|x,y| break "b"}' > d> "start" > > d> I'm still not understanding why these should be different, or how > d> "start" gets into the first one (the first block) at all. > > svg% ruby -e 'p ["x", "y"].inject("a") {|x,y| break 12 if y == "y"; x + y}' > "ax" > svg% > > #inject ignore the value returned by break, and return the last result. I thought "break val" executed a break *and* generated a return value for the block at the same time: irb(main):011:0> a = proc { break 3 } .call; a => 3 Why wouldn't #inject treat the break the same way? David -- David Alan Black home: dblack@superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav