J
Just Another Victim of the Ambient Morality
I'm not sure how I feel about inject's pathological case. What do you
all think should happen in the following code?
[2].inject {|a, i| puts i}
I might have thought that the block would never be called and the method
would return 2.
If the block must be called, I might expect "i" to be nil.
What actually happens is that the block is called and "i" is the same
thing as "a". I did not expect this and I'm trying to figure out how this
is either consistent or useful. Can someone clue me in to this behaviour?
Thank you...
all think should happen in the following code?
[2].inject {|a, i| puts i}
I might have thought that the block would never be called and the method
would return 2.
If the block must be called, I might expect "i" to be nil.
What actually happens is that the block is called and "i" is the same
thing as "a". I did not expect this and I'm trying to figure out how this
is either consistent or useful. Can someone clue me in to this behaviour?
Thank you...