public def my_inject(n = 0) accumulator = n self.each{|i| accumulator = yield(accumulator, i)} return accumulator end print [2, 3, 4].my_inject{|memo, item| memo + item}
Standard input is empty
Standard output is empty
prog.rb:9:in `block in <main>': undefined method `+' for nil:NilClass (NoMethodError) from prog.rb:5:in `block in my_inject' from prog.rb:5:in `each' from prog.rb:5:in `my_inject' from prog.rb:9:in `<main>'