Last Updated: February 25, 2016
·
367
· mejarc

Ruby inject

Use for very shorthand arithmetic. For instance, instead of

def multiply(num1, num2)
  num1 * num2
 ...

use inject:

def multiply(*nums)
  nums.inject(:*)
....