From: dblack@... Date: 2003-10-07T11:21:56+09:00 Subject: Re: Enumerable#inject is surprising me... Hi -- On Tue, 7 Oct 2003 nobu.nokada@softhome.net wrote: > At Tue, 7 Oct 2003 08:39:34 +0900, > Weirich, James wrote: > > > > ['a'].inject(''){break 'b'} # => 'b' > > But this doesn't work as Nathaniel expected. It returns last > iteration value, "". I'm not sure why it would be "". Wouldn't that only happen if the empty string (the inject accumulator) appeared as the last value in the block? For example: irb(main):010:0> [].inject('') { |a| a } => "" I'm also looking at these two cases: irb(main):002:0> ['a'].inject('') { } => nil irb(main):003:0> ['a'].inject('') { 'b' } => "b" Doesn't "break 'b'" evaluate to 'b' (even though of course it also breaks)? David -- David Alan Black home: dblack@superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav