Skip to Content Skip to Search

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
#
E
F
I
K
N
O
P
T

Class Public methods

new(parent = nil)

# 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

Instance Public methods

==(other)

# File activesupport/lib/active_support/ordered_options.rb, line 117
def ==(other)
  other.is_a?(Hash) && to_h == other.to_h
end

_own_keys()

Alias for: keys

each(&block)

# File activesupport/lib/active_support/ordered_options.rb, line 156
def each(&block)
  to_h.each(&block)
  self
end

freeze()

# File activesupport/lib/active_support/ordered_options.rb, line 103
def freeze
  return self if frozen?

  @own_keys = own_keys.dup.freeze
  self.default_proc = nil
  @parent.freeze
  replace(to_h)
  super
end

inheritable_copy()

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

inspect()

# File activesupport/lib/active_support/ordered_options.rb, line 121
def inspect
  "#<#{self.class.name} #{to_h.inspect}>"
end

key?(key)

# File activesupport/lib/active_support/ordered_options.rb, line 133
def key?(key)
  super || @parent.key?(key)
end

keys()

Also aliased as: _own_keys
# File activesupport/lib/active_support/ordered_options.rb, line 140
def keys
  @parent.keys | super
end

overridden?(key)

# File activesupport/lib/active_support/ordered_options.rb, line 144
def overridden?(key)
  !!(@parent && @parent.key?(key) && own_key?(key.to_sym))
end

pretty_print(pp)

# File activesupport/lib/active_support/ordered_options.rb, line 129
def pretty_print(pp)
  pp.pp_hash(to_h)
end

to_a()

# File activesupport/lib/active_support/ordered_options.rb, line 152
def to_a
  entries
end

to_h()

# File activesupport/lib/active_support/ordered_options.rb, line 113
def to_h
  @parent.to_h.merge(self)
end

to_s()

# File activesupport/lib/active_support/ordered_options.rb, line 125
def to_s
  to_h.to_s
end