Given,
def wrapper &block
(1..5).inject yield
end
proc = Proc.new {|sum, n| sum + n }
Why can't I do this call?
wrapper &proc
=> NoMethodError: undefined method `+' for nil:NilClass
When looking inside, I see that inject has not been able to assign the memo or the obj, as rewriting the proc to be proc = Proc.new {|memo, obj| puts memo ; puts obj }
returns 10 iterations of nothing. I also noted that (1..5).inject
takes only one argument, what it passes in as the initial memo, and that technically it doesn't the block as a real argument.