Skip to content

Instantly share code, notes, and snippets.

@gerep
Created October 1, 2013 18:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save gerep/6782680 to your computer and use it in GitHub Desktop.
Save gerep/6782680 to your computer and use it in GitHub Desktop.
def self.total_volume(transactions)
total = 0
if transactions.is_a?(Array)
transactions.each do |transaction|
total += transaction.amount
end
else
total += transactions.amount
end
total
end
@gerep
Copy link
Author

gerep commented Oct 1, 2013

  def self.total_volume(transactions)
    return transactions.amount unless transactions.is_a? Array
    transactions.reduce(0) do |total, transaction|
      total += transaction.amount
    end
  end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment