From: benjohn@... Date: 2007-02-20T19:47:25+09:00 Subject: Re: Help with Class design > And to that end, using the suggestions above, I suppose I could equally > well write : > > def variance() > @signal.inject(0) { |var, x| var += (x - mean) ** 2 } / > (@signal.length-1) > end > > removing the assignment "m = mean" ? I wrote about removing the "m=mean" in another post... I don't think the above will work, and even if it does, I would advise very strongly against putting an assignment in to your inject block. It breaks the semantics of what people (well, me anyway) expect inject to do. What you're trying to do with inject is make a more "functional" program; you're trying to avoid assigning to things; you're closer to saying what you want done, rather than how you want it done (declarative verses imperative style). If you start making assignments, you break away from that style.