/yield_example.rb Secret
Created
March 15, 2021 15:17
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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