Skip to content

Instantly share code, notes, and snippets.

@dcyoung-dev
Created Mar 15, 2021
Embed
What would you like to do?
class Loan
attr_accessor :outstanding_balance, :remaining_months, :monthly_repayments
def save!
end
end
def some_calculation
10
end
def make_change(loan:, &block)
yield loan if block_given?
loan.monthly_repayments = some_calculation
loan.save
end
new_loan = Loan.new
make_change(loan: new_loan) do |yielded_loan|
yielded_loan.outstanding_balance = 100_00
end
make_change(loan: new_loan) do |yielded_loan|
yielded_loan.remaining_months = 100
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment