# savings.rb
#
# Savings account example that inherits from Account class in account.rb

require_relative 'account'   # look in current directory for account.rb,
                             # which contains the Account class definition

class Savings_Account < Account       # inherit from Account class

    # Notice:  no "attr_accessor :balance", because we're inheriting
    # the instance variable and the getter/setter from Account

            # We don't need to override the constructor, but I did to
            # show (a) that you can, and (b) that 'super' invokes the
            # superclass' constructor.

    def initialize initial_balance = 1
        super(initial_balance)
    end

            # Only point of this method is to show that @balance is
            # available, should we wish to access it directly.
            # Alternative:  self.balance

    def in_cents
        @balance*100
    end

end


# Testing...

begin
    s = Savings_Account.new(20)
    puts "Account balance is $#{s.balance}"           # using inherited getter
    puts "Or, your balance is #{s.in_cents} cents."
end if $0 == "savings.rb"
