ruby self.included用法

===Module#included 
當一個模塊混入到類時,若是該模塊的included方法已經定義,那麼該方法被調用。該方法的惟一參數就是接受混含的類的名字。 spa

 1 module M 
 2 def self.included(c) 
 3     puts "I have justbeen mixed into #{c}." 
 4 end 
 5 end 
 6 
 7 
 8 class C 
 9 include M 
10 end 

也就是說當類c中執行include M時,調用self.included方法code

相關文章
相關標籤/搜索