p acc, .
(arup~>~)$ pry --simple-prompt
>> module Enumerable
| def injecting(*acc, &block)
| acc = acc.empty? ? self.shift : acc.first
| p acc
| self.each do |x|
| acc = block.call(acc, x)
| end
| acc
| end
| end
=> nil
>> [1,2,3].injecting { |a,x| a + x }
1
=> 6
>>
injecting [1,2,3], acc , sef.shift. acc - 1. self [2,3]. self.each.. 2, , a = x acc, 3. , self (3), , a + x, acc 6. , 6.
:
(arup~>~)$ pry --simple-prompt
>> module Enumerable
| def injecting(*acc, &block)
| acc = acc.empty? ? self.shift : acc.first
| p "acc now holds #{acc}"
| p "elements in self is #{self}"
| self.each do |x|
| acc = block.call(acc, x)
| p "current value of acc is #{acc}"
| end
| acc
| end
| end
=> nil
>> [1,2,3].injecting { |a,x| a + x }
"acc now holds 1"
"elements in self is [2, 3]"
"current value of acc is 3"
"current value of acc is 6"
=> 6
>>
OP
, 1- , , 7?
, , . :
(arup~>~)$ pry --simple-prompt
>> module Enumerable
| def injecting(*acc, &block)
| acc = acc.empty? ? self.first : acc.first
| p "acc now holds #{acc}"
| p "elements in self is #{self}"
| self.each do |x|
| acc = block.call(acc, x)
| p "current value of acc is #{acc}"
| end
| acc
| end
| end
=> nil
>> [1,2,3].injecting { |a,x| a + x }
"acc now holds 1"
"elements in self is [1, 2, 3]"
"current value of acc is 2"
"current value of acc is 4"
"current value of acc is 7"
=> 7
>>
self.first , 1, acc. . self.shift, 1 acc, self, self [2,3].
self.each.. 3 self, 1, 2 3. 6 1, acc, self.first. acc 7.