Created
June 18, 2013 22:27
-
-
Save mattmawhinney/5810058 to your computer and use it in GitHub Desktop.
More Ruby practice from Codeacademy working on using private methods
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 Account | |
attr_reader :name | |
attr_reader :balance | |
def initialize(name, balance = 100) | |
@name = name | |
@balance = balance | |
end | |
def display_balance(pin_number) | |
if pin_number == pin | |
puts "Balance: #{@balance}" | |
else | |
puts | |
pin_error | |
end | |
end | |
def withdraw(pin_number, amount) | |
if pin_number == pin | |
@balance -= amount | |
puts "Withdrew #{amount}. New balance: $#{@balace}." | |
else | |
puts pin_error | |
end | |
end | |
private | |
def pin | |
@pin = 1234 | |
end | |
def pin_error | |
return "Access denied: incorrect PIN." | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment