Banking on Ruby


#1

I’m on Exercise 6 on the Banking on Ruby section in the Ruby Codecademy lesson. However I keep getting syntax errors. Please tell my what I’m doing wrong.

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

  private
  def pin
    @pin = 1234
  end
  
  def pin_error
    return "Access denied: incorrect PIN."
  end 
end

  def display_balance(pin_number)
    if pin_number = pin
      puts "Balance: $#{@balance}."
    else
      puts pin_error
    end

  def withdraw(pin_number, amount)
    if pin_number == pin
      @balance -= amount
      puts "Withdrew #{amount}. New balance: $#{@balance}."
    else
      puts pin_error
    end
  end

checking_account = Account.new("Emily", 9_999_999)


#2

Shouldn’t all your methods be inside the class?


#3

Are they not all under the class?


#4

Indentation is absolutely crucial.

Mind an end that closes the class, leaving other methods out.


#5

I looked at the ends and indentations, and I got the code. Thanks for your help!