I am trying to rewrite these three functions in a single one:
def self.net_amount_by_year(year)
year(year).map(&:net_amount).sum
end
def self.taxable_amount_by_year(year)
year(year).map(&:taxable_amount).sum
end
def self.gross_amount_by_year(year)
year(year).map(&:gross_amount).sum
end
Can anybody help?
This is what I've got so far:
def self.amount_by_year(type_of_amount, year)
year(year).map(&type_of_amount.to_sym).sum
end
The &type_of_amount
bit doesn't work of course. And I wonder how to do that.
Thanks for any help.
P.S.: By the way, I don't even know what the &
is for. Can anybody explain?