sonic-pi
https://github.com/sonic-pi-net/sonic-pi
C++
Code. Music. Live.
Enumerable#sum
Calculates a sum from the elements.
payments.sum { |p| p.price * p.tax_rate }
payments.sum(&:price)
The latter is a shortcut for:
payments.inject(0) { |sum, p| sum + p.price }
It can also calculate the sum without the use of a block.
[5, 15, 10].sum # => 30
['foo', 'bar'].sum # => "foobar"
[[1, 2], [3, 1, 5]].sum => [1, 2, 3, 1, 5]
The default sum of an empty list is zero. You can override this default:
[].sum(Payment.new(0)) { |i| i.amount } # => Payment.new(0)Edit
git clone [email protected]:sonic-pi-net/sonic-pi.git
cd sonic-pi
open app/server/ruby/vendor/activesupport-7.0.6/lib/active_support/core_ext/enumerable.rb
Contribute
# Make a new branchgit checkout -b -your-name--update-docs-Enumerable-sum-for-pr
# Commit to gitgit add app/server/ruby/vendor/activesupport-7.0.6/lib/active_support/core_ext/enumerable.rbgit commit -m "better docs for Enumerable#sum"
# Open pull requestgem install hub # on a mac you can `brew install hub`
hub fork
git push <your name> -your-name--update-docs-Enumerable-sum-for-pr
hub pull-request
# Celebrate!