可繼承選項
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'
方法
- #
- E
- I
- K
- N
- O
- P
- T
類別公開方法
new(parent = nil) 連結
程式碼: 顯示 | 在 GitHub 上
# File activesupport/lib/active_support/ordered_options.rb, line 90 def initialize(parent = nil) @parent = parent 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() @parent = {} end end
實例公開方法
==(other) 連結
程式碼: 顯示 | 在 GitHub 上
# File activesupport/lib/active_support/ordered_options.rb, line 107 def ==(other) to_h == other.to_h end
each(&block) 連結
程式碼: 顯示 | 在 GitHub 上
# File activesupport/lib/active_support/ordered_options.rb, line 142 def each(&block) to_h.each(&block) self end
inheritable_copy() 連結
程式碼: 顯示 | 在 GitHub 上
# File activesupport/lib/active_support/ordered_options.rb, line 134 def inheritable_copy self.class.new(self) end
inspect() 連結
程式碼: 顯示 | 在 GitHub 上
# File activesupport/lib/active_support/ordered_options.rb, line 111 def inspect "#<#{self.class.name} #{to_h.inspect}>" end
key?(key) 連結
別名: own_key?
程式碼: 顯示 | 在 GitHub 上
# File activesupport/lib/active_support/ordered_options.rb, line 126 def key?(key) super || @parent.key?(key) end
overridden?(key) 連結
程式碼: 顯示 | 在 GitHub 上
# File activesupport/lib/active_support/ordered_options.rb, line 130 def overridden?(key) !!(@parent && @parent.key?(key) && own_key?(key.to_sym)) end
pretty_print(pp) 連結
程式碼: 顯示 | 在 GitHub 上
# File activesupport/lib/active_support/ordered_options.rb, line 119 def pretty_print(pp) pp.pp_hash(to_h) end
to_a() 連結
程式碼: 顯示 | 在 GitHub 上
# File activesupport/lib/active_support/ordered_options.rb, line 138 def to_a entries end
to_h() 連結
程式碼: 顯示 | 在 GitHub 上
# File activesupport/lib/active_support/ordered_options.rb, line 103 def to_h @parent.merge(self) end
to_s() 連結
程式碼: 顯示 | 在 GitHub 上
# File activesupport/lib/active_support/ordered_options.rb, line 115 def to_s to_h.to_s end