(ruby):31: syntax error, unexpected $end, expecting keyword_end


#1



5.19


(ruby):31: syntax error, unexpected $end, expecting keyword_end

I seriously do not understand what's wrong here. I'd appreciate SOOO MUCH if someone can explain why I'm getting this error message. I've moved the "end" on line 32 around a bunch of times. I've also completely removed it. I've condensed the code (know it can be condensed more), put all public methods together. I honestly see nothing wrong here. I'm hoping those of you who are infinitely more versed in Ruby can help me out and tell me what's wrong. So frustrating to be this close and feel so stupid.


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
    
  def withdraw(pin_number, amount)
    if pin_number == pin
      @balance -= amount
      puts "Withdrew #{amount}. New balance: $#{@balance}."
    else
      puts pin_error
  end    
  
  private
    def pin
      @pin = 1234
    end
    
    def pin_error
      return "Access denied: incorrect PIN."
    end
  end
end


#2

Hey pay close attention to your end statements.
Look at your display_balance and withdraw methods. Anything missing at the end?


#3

OMG!!!!

Literally lol'd for a solid 3 mins before replying, thank you so much. Idk if i feel less or more like an idiot now. The number of times I looked this code over and didn't notice is embarrasing.

So many thanks!!


#4

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