3 ms·
Methods that simply behave differently depending on whether or not an argument is given. For example, passing nil (or any other object) to inject is different f
by Mon_Ouie 14y ago
Methods that simply behave differently depending on whether or not an argument is given. For example, passing nil (or any other object) to inject is different from passing nothing.
[1, 2, 3].inject(:+)
[1, 2, 3].inject(0, :+)
[1, 2, 3].inject(nil, :+) # doesn't work
Rubinius uses a magic ``undefined`` value for this:
def inject(initial=undefined, sym=undefined, &block)