Class: ActiveSupport::InheritableOptions
- Inherits:
-
OrderedOptions
- Object
- Hash
- OrderedOptions
- ActiveSupport::InheritableOptions
- Defined in:
- activesupport/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!, #with_indifferent_access
Constructor Details
#initialize(parent = nil) ⇒ InheritableOptions
Returns a new instance of InheritableOptions.
52 53 54 55 56 57 58 59 60 61 |
# File 'activesupport/lib/active_support/ordered_options.rb', line 52 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
63 64 65 |
# File 'activesupport/lib/active_support/ordered_options.rb', line 63 def inheritable_copy self.class.new(self) end |