Ruby inject
Use for very shorthand arithmetic. For instance, instead of
def multiply(num1, num2)
num1 * num2
...
use inject
:
def multiply(*nums)
nums.inject(:*)
....
Written by Melanie Archer
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Related Tags
#ruby
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#