From: Amir Ebrahimifard on
Hi
In inject method , everytime that inject called what is returned ? for
example in this code everytime what is returned ?

array = [*1..10]
array.inject(0) { | memo , item | memo + item }
--
Posted via http://www.ruby-forum.com/.

From: brabuhr on
On Tue, Aug 3, 2010 at 1:55 PM, Amir Ebrahimifard <amiref(a)ymail.com> wrote:
> In inject method , everytime that inject called what is returned ? for
> example in this code  everytime what is returned ?
>
> array = [*1..10]
> array.inject(0) { | memo , item | memo + item }

irb(main):001:0> array = [*1..10]
=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
irb(main):002:0> array.inject(0) { | memo , item | puts
"#{memo}\t#{item}"; memo + item }
0 1
1 2
3 3
6 4
10 5
15 6
21 7
28 8
36 9
45 10
=> 55