class BankAccount

Attributes

balance[RW]
loan_amt[RW]
name[RW]

Public Class Methods

new(balance=10000, loan_amt=0, name="Priyanka") click to toggle source
# File lib/bank_account_attr.rb, line 6
def initialize(balance=10000, loan_amt=0, name="Priyanka")
        @balance = balance
        @loan_amt = loan_amt
        @name = name
end
transfer(acc1,acc2) click to toggle source
# File lib/bank_account_attr.rb, line 42
def self.transfer(acc1,acc2)
        print "Enter the account holder name you want transfer: "
        @name = gets.chomp.to_s
        print "Enter the amount for: "
        amount = gets.chomp.to_i
        if amount > acc1.balance
                puts "Transaction failed.You have no enough money for the transaction." 
        else
                acc1.balance = acc1.balance - amount
                acc2.balance = acc2.balance + amount
                puts "Your current balance after transfer is #{acc1.balance}"
        end   
end

Public Instance Methods

current_bal() click to toggle source
# File lib/bank_account_attr.rb, line 25
def current_bal
        puts "#{name},your current balance is: #{@balance}"
end
deposite() click to toggle source
# File lib/bank_account_attr.rb, line 11
def deposite
        puts "#{name},your previous balance is: #{@balance}"
        print "Enter the amount you want to deposite: "
        dip = gets.chomp.to_i
        @balance = @balance + dip
        puts "Your current balance is: #{@balance}"
end
loan() click to toggle source
# File lib/bank_account_attr.rb, line 28
def loan
        puts "#{name},your current balance is: #{@balance}"
        print "Enter the amount you want for loan: "
        lon = gets.chomp.to_i
        @loan_amt = @loan_amt + lon
        puts "You get the loan of: #{@loan_amt}"
end
loan_paid() click to toggle source
# File lib/bank_account_attr.rb, line 35
def loan_paid
        puts "#{name},your current loan amount is: #{@loan_amt}"
        print "Enter the amount you want to pay for loan: "
        lon = gets.chomp.to_i
        @loan_amt = @loan_amt - lon
        puts "Your current balance with loan amount is: #{@loan_amt+@balance} "
end
withdraw() click to toggle source
# File lib/bank_account_attr.rb, line 18
def withdraw
        puts "#{name},your previous balance is: #{@balance}"
        print "Enter the amount you want to withdraw: "
        wid = gets.chomp.to_i
        @balance = @balance - wid
        puts "Your current balance is: #{@balance}"
end