2008年4月30日 星期三

module

 module is like class,  but it can not be instantiated
 support methods for other class
 
use include to include module

a class can only have inherit from one class, but it can mix in more than one mouels

ex:
module Animal
    def   test
    ned
end 

class Rabbit
      include Animal
      def  run
           test
     end
end

if a class include two modules,  M1 & M2( M2 is included last),
M1 & M2 both have method test
When the object of the class calls method test,
it will call M2's test

沒有留言: