1
如何從外部訪問以下代碼中的reserved_words
?如何從外部調用模塊的attr_accessor變量?
module FriendlyId
module Reserved
module Configuration
attr_accessor :reserved_words
end
end
end
做FriendlyId::Reserved::Configuration.instance_variable_get(:reserved_words)
給了我以下錯誤:
NameError: 'reserved_words' is not allowed as an instance variable name
您是否特別需要'attr_accessor'或者您可以使用rails提供的擴展名'mattr_accessor'(http://api.rubyonrails.org/classes/Module.html#method-i-mattr_accessor) – Shadwell
試試這個:: FriendlyId :: Reserved :: Configuration.instance_variable_get(:reserved_words) – Egalitarian
檢查此線程http://stackoverflow.com/questions/185573/what-is-mattr-accessor-in-a-rails-module – xlembouras