Skip to content

Instantly share code, notes, and snippets.

@mattmawhinney
Created June 18, 2013 22:27
Show Gist options
  • Save mattmawhinney/5810058 to your computer and use it in GitHub Desktop.
Save mattmawhinney/5810058 to your computer and use it in GitHub Desktop.
More Ruby practice from Codeacademy working on using private methods
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