Comment by jdougan
12 hours ago
Ruby inject appears to be derived from Smalltalk #inject:into:
#(1 2 3 4 5 6 7) inject: 10 into: [ :sum :each | sum + each squared ].
or from your example:
someHash := myArray inject: (Dictionary new) into: [ :accumulator :item | ... ].
The way I remember the order is it reflects the assignment you'd do is a while loop, sum := sum + each.
No comments yet
Contribute on Hacker News ↗