[Newbies] Re: How to shorten a method (using inject: into: ?)
me at zulq.net
Mon Jul 21 14:35:55 UTC 2008
How about using #detectSum:?
pTotal := Forecaster testMale meiose
detectSum: [:strand | strand testRun paternalCount].
mTotal := Forecaster testMale meiose
detectSum: [:strand | strand testRun maternalCount].
self should: [mTotal = 100 and: [pTotal = 100]]
Other methods of this variety include #detectMin:, #detectMax: and
#count: and possibly others.
stan shepherd wrote:
> Hi, I have the following method, that code critics flags as long:
> | testSet mCount pCount mTotal pTotal |
> pTotal := 0.
> mTotal := 0.
> Forecaster testMale meiose
> do: [:strand |
> testSet := strand testRun.
> mCount := testSet maternalCount.
> pCount := testSet paternalCount.
> mTotal := mTotal + mCount.
> pTotal := pTotal + pCount].
> should: [mTotal = 100
> and: [pTotal = 100]]
> I'm trying to shorten it, including various attempts with inject: into: ,
> but with no success. Any tips please?
More information about the Beginners