Static class method : Class Methods « Class « Ruby






Static class method


#!/usr/bin/env ruby

class Area

  def Area.rect( length, width, units="inches" )
    area = length*width
    printf( "The area of this rectangle is %.2f %s.", area, units )
    sprintf( "%.2f", area )
  end

end

Area.rect( 12.5, 16 )

 








Related examples in the same category

1.Creating Class Methods
2.The area method is made available in all objects of class Square,
3.Class methods give you the mechanism to properly implement the object counter