我正在製作一個Rails小程序,其中包含我在ApplicationHelper
模塊內部的模塊內部構建的一些方法。這裏有一個例子:使模塊繼承Ruby中的另一個模塊
module Helper
def time
Time.now.year
end
end
module ApplicationHelper
# Inherit from Helper here...
end
我知道ApplicationHelper < Helper
和include Helper
會一類的環境中工作,但你會使用模塊到模塊繼承?謝謝。
我從來沒有想過在另一個模塊內部使用模塊,感謝您的幫助! – beakr 2012-04-15 01:15:20
我不確定ApplicationHelper裏面的Helper聲明是什麼,除了把它從全局代碼中隱藏起來。重要的是'include'(和'extend')適用於模塊和類。 – 2012-04-15 05:08:38