3. Private Affairs


#1

I don't understand what is wrong in my code, someone can help me ?
I have to do :
Add two private methods to your Account class, pin and pin_error.
pin should take no arguments and set an instance variable, @pin, equal to the PIN number 1234.
pin_error should take no arguments and should simply return the string "Access denied: incorrect PIN."

I have written :
1 class Account
2 attr_reader :name
3 attr_reader :balance
4 def initialize(name, balance=100)
5 @name = name
6 @balance = balance
7 end
8 private
9 def pin
10 @pin = 1234
11 end
12 private
13 def pin_error
14 return "Access denied: incorrect PIN."
15 end

and it says me :

(ruby):14: syntax error, unexpected $end, expecting keyword_end
Oops, try again. Your code doesn't look quite right. Feel free to peek back at the code in the first exercise if you need help!

Thank you for your help!!


#2

Hi you just forgot to put the end to you def pin_error


#3

ho...

Thank you for your anwer !


#4

Try this code:

class Account
attr_reader :name
attr_reader :balance
def initialize(name, balance=100)
@name = name
@balance = balance
end
private

def pin
@pin = 1234
end

def pin_error
"Access denied: incorrect PIN."
end
end