fork download
  1. public
  2.  
  3. def my_inject(n = 0)
  4. accumulator = n
  5. self.each{|i| accumulator = yield(accumulator, i)}
  6. return accumulator
  7. end
  8.  
  9. print [2, 3, 4].my_inject{|memo, item| memo + item}
Runtime error #stdin #stdout #stderr 0.05s 9640KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
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>'