跳至内容 跳至搜索

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