class BankAccount
def self.create_for(first_name, last_name)
@accounts ||= []
@accounts << BankAccount.new(first_name, last_name)
end
def initialize(first_name, last_name)
@balance = 0
@first_name = first_name
@last_name = last_name
end
def self.find_for(first_name, last_name)
@accounts.find{|account| account.full_name == "#{first_name} #{last_name}"}
end
def full_name
"#{@first_name} #{@last_name}"
end
end
How does the method self.find_for works?. I am getting confused on how the account variable has access to full_name method?.
bankacc = BankAccount.create_for "Kevin", "Shane"
BankAccount.find_for("Kevin", "Shane")
puts bankacc.inspect
full_nameis a simple instance method andaccountis an instance ofBankAccount, so you can call the instance mehtodfull_nameon it.