The exercise asks you to do the following:
Blockquote
Define a public display_balance method to your Account class. It should take a single parameter, pin_number. The body of your method should check whether the pin_number is equal to pin (the result of calling the private pin method). If it is, display_balance should puts “Balance: $#{@balance}.” Otherwise (else), it should puts pin_error (the pin_error message)."
Here is my code. I am not sure why it is that when I run the code, I get an output of Balance = $500.
class Account
attr_reader :name
attr_reader :balance
def initialize(name, balance=100)
@name = name
@balance = balance
end
private
def pin
@pin = 1234
end
private
def pin_error
return "Access denied: incorrect PIN."
end
public
def display_balance(pin_number)
if pin_number = pin
puts "Balance: $#{@balance}."
else
puts pin_error
end
end
end
But the exercise has this code for display_balance method
def display_balance(pin_number)
puts pin_number == pin ? "Balance: $#{@balance}." : pin_error
end
when I use the same code and run it then I don’t get any output, which I am assuming is how it should be. Why does my code give an output? Am I doing something wrong?
Thanks