Tell me more ×  I find this code in Ruby to be pretty intriguing
Ok, I know what inject does, and I know this code is basically
equivalent to  (1..4).inject(0) {|a,n| a + n}  but how exactly
does it work?  Why &:+ is the same as writing the block {|a,n| a
+ n}?  Why it doesn't need an initial value? I'm ok with the
inicial value being 0, but (1..4).inject(&:*) also works, and
there the initial value must be 1...  share|improve this
question These are really two completely separate questions, the
first one of which is a duplicate of no less than 11 other
questions that have already been asked and answered here on
StackOverflow: StackOverflow.Com/q/99318
StackOverflow.Com/q/1217088 StackOverflow.Com/q/1792683
StackOverflow.Com/q/1961030 StackOverflow.Com/q/2096975
StackOverflow.Com/q/2211751 StackOverflow.Com/q/2259775
StackOverflow.Com/q/2388337 StackOverflow.Com/q/2697024
StackOverflow.Com/q/3888044 StackOverflow.Com/q/4512587 –  Jörg
W Mittag Feb 15 '11 at 18:46 add comment  1 Answer  up vote 7
down vote a