Posted By

gnatware on 02/04/07


Tagged

array inject


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

bbebop
webstic


Lots of Array methods


 / Published in: Ruby
 

URL: http://www.therailsway.com/2007/1/10/assetsgraphed-part-2

  1. # use Array#inject to calculate totals
  2.  
  3. def number_of_incomings
  4. assets.inject(0) {|total, asset| total += asset.incomings.size }
  5. end

Report this snippet  

You need to login to post a comment.