Afficher un message
Vieux 30/03/2008, 07h13   #1
Just Another Victim of the Ambient Morality
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut inject's pathological case...

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...



  Réponse avec citation
 
Page generated in 0,04232 seconds with 9 queries