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 ==
<source>
  class Account1
class Account1
    @balance
  @balance
    @name
  @name
    
    
  attr_accessor :balance
    attr_accessor :balance
  attr_accessor :name
    attr_accessor :name
    
    
  def initialize(amount)
    def initialize(amount)
    @balance = amount
      @balance = amount
  end
    end
    
    
  def deposit(amount)
    def deposit(amount)
    @balance += increase
      @balance += increase
  end
    end


  def addinterest(rate)
    def addinterest(rate)
    @balance *= (1 + interest)
      @balance *= (1 + interest)
  end
    end
    
    
  def withdrawal(amount)
    def withdrawal(amount)
    @balance -= amount
      @balance -= amount
  end
    end


  def hasName()
    def hasName()
    return @name != nil
      return @name != nil
    end
   end
   end
end
myAccount = Account.new(100)
myAccount.withdrawal(20)
puts myAccount.balance
puts myAccount.hasName
</source>

Revision as of 14:53, 17 September 2011

Ruby Testing Frameworks

Demo Code

 class Account1
   @balance
   @name
 
   attr_accessor :balance
   attr_accessor :name
 
   def initialize(amount)
     @balance = amount
   end
 
   def deposit(amount)
     @balance += increase
   end
   def addinterest(rate)
     @balance *= (1 + interest)
   end
 
   def withdrawal(amount)
     @balance -= amount
   end
   def hasName()
     return @name != nil
   end
 end