Blocks
Enumerable Reports
Imported from the upstream Vibescript examples at blocks/enumerable_reports.vibe and runnable in the browser today.
Source
blocks/enumerable_reports.vibe
# vibe: 0.2
def total_raised_by_currency(donations)
grouped = {}
donations.each do |donation|
currency = donation[:amount].currency
current = grouped[currency]
if current == nil
current = money("0.00 " + currency)
end
grouped[currency] = current + donation[:amount]
end
grouped
end
def run
donations = [
{ amount: money("25.00 USD") },
{ amount: money("50.00 USD") },
{ amount: money("10.00 USD") }
]
total_raised_by_currency(donations)
end
Output
Press run to execute run from this example.