CSC/ECE 517 Fall 2011/ch2 2e kt: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
Line 2: Line 2:
== Ruby Testing Frameworks ==
== Ruby Testing Frameworks ==
== Demo Code ==
== Demo Code ==
   class Account1
   class Account
     @balance
     @balance
     @name
     @name
Line 16: Line 16:
       @balance += amount
       @balance += amount
     end
     end
 
 
     def addinterest(rate)
     def addinterest(rate)
       @balance *= (1 + rate)
       @balance *= (1 + rate)
Line 23: Line 23:
     def withdrawal(amount)
     def withdrawal(amount)
       @balance -= amount
       @balance -= amount
    end
    def hasName()
      return @name != nil
     end
     end
   end
   end

Revision as of 15:41, 17 September 2011

Ruby Testing Frameworks

Demo Code

 class Account
   @balance
   @name
 
   attr_accessor :balance
   attr_accessor :name
 
   def initialize(amount)
     @balance = amount
   end
 
   def deposit(amount)
     @balance += amount
   end
 
   def addinterest(rate)
     @balance *= (1 + rate)
   end
 
   def withdrawal(amount)
     @balance -= amount
   end
 end