From: "Simon Kröger" Date: 2007-08-04T20:20:00+09:00 Subject: Re: Running multiple closures per iteration Tim Pease schrieb: > On 8/3/07, Joshua Chia wrote: >> Joel VanderWerf wrote: >>> Did you mean >>> >>> o = a.select {|x| x >= 0} >>> p = o.inject(0) {|s, x| s += x} >>> ^^^ >>> ? >>> >> No, I meant to compute two different things from a. > > Well, it's not pretty, but here's my best shot at it > > o, p = a.inject( [[], 0] ) do |ary,x| > ary[0] << x if x >= 0 > ary[1] += x > ary > end you can beautify this to o, p = a.inject( [[], 0] ) do |(l, s), x| [x >= 0 ? l << x : l, s + x] end > I don't think Ruby natively supports such a creature, though. Please > correct me if I'm wrong. Well, depends on what 'natively' realy means... > Blessings, > TwP cheers Simon