[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...

matz

10/20/2003 9:25:00 AM

Hi,

In message "Re: Enumerable#inject is surprising me..."
on 03/10/07, dblack@superlink.net <dblack@superlink.net> writes:

|> > ['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?

It's a bug. I fixed it in the latest CVS.

matz.

2 Answers

Robert Klemme

10/20/2003 11:26:00 AM

0


"Yukihiro Matsumoto" <matz@ruby-lang.org> schrieb im Newsbeitrag
news:1066641883.530342.13684.nullmailer@picachu.netlab.jp...
> Hi,
>
> In message "Re: Enumerable#inject is surprising me..."
> on 03/10/07, dblack@superlink.net <dblack@superlink.net> writes:
>
> |> > ['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?
>
> It's a bug. I fixed it in the latest CVS.
>
> matz.

Sorry if I'm beeing stupid, but I still don't understand why
['a'].inject(''){break 'b'} should not return 'b'. Could you please
clarify this to me? Thank you.

Kind regards

robert

Christoph

10/20/2003 11:54:00 AM

0

Robert Klemme wrote:
....
> Sorry if I'm beeing stupid, but I still don't understand why
> ['a'].inject(''){break 'b'} should not return 'b'. Could you please
> clarify this to me? Thank you.

Don't worry with the fix the snipped returns "b".

Ps. I like to think that this is only more a matter of (good)
taste (I seem to lack anyway:-( ) since I tend to prefer the
previous return value ''.

/Christoph