Displaying the Balance



the relevant part of this code is the display_balance method, but i ve included the code in its entirety. It is exactly the same as in the original code in part one as far as i see but doesnt work and gives the following error.

    puts pin_number==pin? "Balance: $#{@balance}.": pin_error

(ruby):19: syntax error, unexpected ':', expecting keyword_end
puts pin_number==pin? "Balance: $#{@balance}.": pin_error

class Account
    attr_reader :name
    attr_reader :balance
    def initialize(name, balance=100)
        @name = name
        @balance = balance
    def pin
        @pin = 1234
    def pin_error
        "Access denied: incorrect PIN."
    def display_balance(pin_number)
        puts pin_number==pin? "Balance: $#{@balance}." : pin_error


Have you tried with space before ? ?


thanks, that worked. i thought white space didnt' count in ruby. are there situations when it does count like this one?


One that comes to mind is .nil?.

if movies[title.to_sym].nil?

In other words, if the title does not exist in the hash, then ...

Another would be .is_a?

if n.is_a? (Object)

Couple more that come to mind,


What you have above is a ternary expression, so the ? is a stand alone operator.


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