跳至內容 跳至搜尋

Active Support 可設定

Configurable 提供 config 方法,用於儲存和擷取設定選項,為 OrderedOptions

命名空間
方法
C

執行個體公開方法

config()

從設定 OrderedOptions 讀取和寫入屬性。

require "active_support/configurable"

class User
  include ActiveSupport::Configurable
end

user = User.new

user.config.allowed_access = true
user.config.level = 1

user.config.allowed_access # => true
user.config.level          # => 1
# File activesupport/lib/active_support/configurable.rb, line 155
def config
  @_config ||= self.class.config.inheritable_copy
end