Class: ActiveSupport::InheritableOptions
- Inherits:
-
OrderedOptions
- Object
- Hash
- OrderedOptions
- ActiveSupport::InheritableOptions
- Defined in:
- lib/active_support/ordered_options.rb
Overview
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'
Direct Known Subclasses
Instance Method Summary collapse
- #inheritable_copy ⇒ Object
-
#initialize(parent = nil) ⇒ InheritableOptions
constructor
A new instance of InheritableOptions.
Methods inherited from OrderedOptions
#[], #[]=, #dig, #extractable_options?, #inspect, #method_missing, #respond_to_missing?
Methods inherited from Hash
#as_json, #assert_valid_keys, #compact_blank, #compact_blank!, #deep_dup, #deep_merge?, #deep_stringify_keys, #deep_stringify_keys!, #deep_symbolize_keys, #deep_symbolize_keys!, #deep_transform_keys, #deep_transform_keys!, #deep_transform_values, #deep_transform_values!, #except, #except!, #extract!, #extractable_options?, from_trusted_xml, from_xml, #reverse_merge, #reverse_merge!, #slice!, #stringify_keys, #stringify_keys!, #symbolize_keys, #symbolize_keys!, #to_query, #to_xml, #with_indifferent_access
Methods included from DeepMergeable
#deep_merge, #deep_merge!, #deep_merge?
Constructor Details
#initialize(parent = nil) ⇒ InheritableOptions
Returns a new instance of InheritableOptions.
94 95 96 97 98 99 100 101 102 103 |
# File '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 |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class ActiveSupport::OrderedOptions
Instance Method Details
#inheritable_copy ⇒ Object
105 106 107 |
# File 'lib/active_support/ordered_options.rb', line 105 def inheritable_copy self.class.new(self) end |