Why is it that the following code runs fine
p (1..1000).inject(0) { |sum, i|
sum + i
}
But, the following code gives an error
This looks like a effect of the difference in binding between do/end and brackets:
brackets, used as you are above, will bind to the last function chained while do/end will bind to the first.
I think thats sort of a odd way to say it, but basically the first instance is passing the block to the function 'inject', while the second is actually trying to pass the block to the first method 'p'.