跳到內容 跳到搜尋

可繼承選項

InheritableOptions 提供一個建構函式來建立一個從另一個雜湊繼承的 OrderedOptions 雜湊。

如果您已經有一些雜湊,並且想要根據它建立一個新的雜湊,請使用這個方法。

h = ActiveSupport::InheritableOptions.new({ girl: 'Mary', boy: 'John' })
h.girl # => 'Mary'
h.boy  # => 'John'

如果現有的雜湊有字串金鑰,請對它呼叫 Hash#symbolize_keys

h = ActiveSupport::InheritableOptions.new({ 'girl' => 'Mary', 'boy' => 'John' }.symbolize_keys)
h.girl # => 'Mary'
h.boy  # => 'John'
方法
I
N

類別公開方法

new(parent = nil)

# File activesupport/lib/active_support/ordered_options.rb, line 94
def initialize(parent = nil)
  if parent.kind_of?(OrderedOptions)
    # use the faster _get when dealing with OrderedOptions
    super() { |h, k| parent._get(k) }
  elsif parent
    super() { |h, k| parent[k] }
  else
    super()
  end
end

實例公開方法

inheritable_copy()

# File activesupport/lib/active_support/ordered_options.rb, line 105
def inheritable_copy
  self.class.new(self)
end