Error when opening an account


#1



https://www.codecademy.com/en/courses/ruby-beginner-en-32cN3/0/6?curriculum_id=5059f8619189a5000201fbcb


I get an error message:
undefined method `attr_reader' for #


class Account
 
    def initialize(name,balance=100)
        attr_reader:name,:balance
        @name = name
        @balance = balance
    end
    
    private
    def pin
        @pin = 1234
    end
    def pin_error
        "Access denied: incorrect PIN"
    end
    
    public
    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: $#{@balance}."
        else
            puts pin_error
        end
    end
end
checking_account = Account.new("din")


#2

Put this code right after your class Account statement,


#3

What @bandit said + add space between attr_reader and its arguments


#4

Thanks! it worked! I just had to put attr_reader right after Class statement :slight_smile:


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.