ActiveSupport::InheritableOptions (original) (raw)

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

I

K

N

O

P

T

Class Public methods

Source: show | on GitHub

def initialize(parent = nil) @parent = parent if @parent.kind_of?(OrderedOptions)

super() { |h, k| @parent._get(k) }

elsif @parent super() { |h, k| @parent[k] } else super() @parent = {} end end

Instance Public methods

Source: show | on GitHub

def each(&block) to_h.each(&block) self end

Source: show | on GitHub

def inheritable_copy self.class.new(self) end

Source: show | on GitHub

def inspect "#<#{self.class.name} #{to_h.inspect}>" end

Source: show | on GitHub

def overridden?(key) !!(@parent && @parent.key?(key) && own_key?(key.to_sym)) end

Source: show | on GitHub

def pretty_print(pp) pp.pp_hash(to_h) end