Inheritable Options
InheritableOptions
provides a constructor to build an OrderedOptions
hash inherited from another hash.
Use this if you already have some hash and you want to create a new one based on it.
h = ActiveSupport::InheritableOptions.new({ girl: 'Mary', boy: 'John' })
h.girl # => 'Mary'
h.boy # => 'John'
If the existing hash has string keys, call Hash#symbolize_keys
on it.
h = ActiveSupport::InheritableOptions.new({ 'girl' => 'Mary', 'boy' => 'John' }.symbolize_keys)
h.girl # => 'Mary'
h.boy # => 'John'
Methods
Class Public methods
new(parent = nil)
📝 Source code
# 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
🔎 See on GitHub
Instance Public methods
==(other)
📝 Source code
# File activesupport/lib/active_support/ordered_options.rb, line 107
def ==(other)
to_h == other.to_h
end
🔎 See on GitHub
each(&block)
📝 Source code
# File activesupport/lib/active_support/ordered_options.rb, line 142
def each(&block)
to_h.each(&block)
self
end
🔎 See on GitHub
inheritable_copy()
📝 Source code
# File activesupport/lib/active_support/ordered_options.rb, line 134
def inheritable_copy
self.class.new(self)
end
🔎 See on GitHub
inspect()
📝 Source code
# File activesupport/lib/active_support/ordered_options.rb, line 111
def inspect
"#<#{self.class.name} #{to_h.inspect}>"
end
🔎 See on GitHub
key?(key)
Also aliased as: own_key?
📝 Source code
# File activesupport/lib/active_support/ordered_options.rb, line 126
def key?(key)
super || @parent.key?(key)
end
🔎 See on GitHub
overridden?(key)
📝 Source code
# File activesupport/lib/active_support/ordered_options.rb, line 130
def overridden?(key)
!!(@parent && @parent.key?(key) && own_key?(key.to_sym))
end
🔎 See on GitHub
pretty_print(pp)
📝 Source code
# File activesupport/lib/active_support/ordered_options.rb, line 119
def pretty_print(pp)
pp.pp_hash(to_h)
end
🔎 See on GitHub
to_a()
📝 Source code
# File activesupport/lib/active_support/ordered_options.rb, line 138
def to_a
entries
end
🔎 See on GitHub
to_h()
📝 Source code
# File activesupport/lib/active_support/ordered_options.rb, line 103
def to_h
@parent.merge(self)
end
🔎 See on GitHub
to_s()
📝 Source code
# File activesupport/lib/active_support/ordered_options.rb, line 115
def to_s
to_h.to_s
end
🔎 See on GitHub