Class: ActiveSupport::InheritableOptions
- Inherits:
-
OrderedOptions
- Object
- Hash
- OrderedOptions
- ActiveSupport::InheritableOptions
- Defined in:
- lib/active_support/ordered_options.rb
Overview
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'
Direct Known Subclasses
Instance Method Summary collapse
- #inheritable_copy ⇒ Object
-
#initialize(parent = nil) ⇒ InheritableOptions
constructor
A new instance of InheritableOptions.
Methods inherited from OrderedOptions
#[], #[]=, #method_missing, #respond_to_missing?
Methods inherited from Hash
#as_json, #assert_valid_keys, #compact, #compact!, #deep_dup, #deep_merge, #deep_merge!, #deep_stringify_keys, #deep_stringify_keys!, #deep_symbolize_keys, #deep_symbolize_keys!, #deep_transform_keys, #deep_transform_keys!, #except, #except!, #extract!, #extractable_options?, from_trusted_xml, from_xml, #reverse_merge, #reverse_merge!, #slice, #slice!, #stringify_keys, #stringify_keys!, #symbolize_keys, #symbolize_keys!, #to_query, #to_xml, #transform_keys, #transform_keys!, #transform_values, #transform_values!, #with_indifferent_access
Constructor Details
#initialize(parent = nil) ⇒ InheritableOptions
Returns a new instance of InheritableOptions.
70 71 72 73 74 75 76 77 78 79 |
# File 'lib/active_support/ordered_options.rb', line 70 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
81 82 83 |
# File 'lib/active_support/ordered_options.rb', line 81 def inheritable_copy self.class.new(self) end |