Methods that iterate over using blocks Specifically, describe as follows
Array.inject {|initial value,element|Processing content}
[1,2,3].inject (0){ |sum, array_num|
p "array_num=#{array_num}"
p sum+=array_num
}
"array_num=1"
1
"array_num=2"
3
"array_num=3"
6
Recommended Posts