我有一個問題,使用acts_as_textiled和has_foreign_language插件在一起。在rails模型中擴展現有的屬性獲取器
的TextElement我在我的應用程序模型
class TextElement < ActiveRecord::Base
has_foreign_language :value
acts_as_textiled :value
HasForeignLanguage
def has_foreign_language(*args)
args.each do |field|
# Define the Getter
define_method(field.to_s) do
.
.
.
ActsAsTextiled
def acts_as_textiled(*attributes)
.
.
.
attributes.each do |attribute|
define_method(attribute) do |*type|
.
.
.
這兩個插件都使用define_method,以及哪種方式我在TextElement中調用mixin,後者覆蓋之前定義的getter。
有沒有辦法保存現有的getter並在新定義的getter中調用它?類似於使用超級如果他們被遺傳。
我已經分出了這些插件,所以這裏都是公平的遊戲。
所有幫助表示讚賞。
你知道這裏發生了什麼嗎? alias_method_chain的文檔非常混亂。 –
請谷歌爲alias_method_chain,它有什麼解釋負載 – Julik