Class: ActiveResource::InheritingHash
- Inherits:
-
Hash
- Object
- Hash
- ActiveResource::InheritingHash
- Defined in:
- lib/active_resource/inheriting_hash.rb
Instance Method Summary collapse
- #[](key) ⇒ Object
-
#initialize(parent_hash = {}) ⇒ InheritingHash
constructor
A new instance of InheritingHash.
- #inspect ⇒ Object
-
#pretty_print(pp) ⇒ Object
So we can see the merged object in IRB or the Rails console.
-
#to_hash ⇒ Object
Merges the flattened parent hash (if it’s an InheritingHash) with ourself.
- #to_s ⇒ Object
Constructor Details
#initialize(parent_hash = {}) ⇒ InheritingHash
Returns a new instance of InheritingHash.
5 6 7 8 9 |
# File 'lib/active_resource/inheriting_hash.rb', line 5 def initialize(parent_hash = {}) # Default hash value must be nil, which allows fallback lookup on parent hash super(nil) @parent_hash = parent_hash end |
Instance Method Details
#[](key) ⇒ Object
11 12 13 |
# File 'lib/active_resource/inheriting_hash.rb', line 11 def [](key) super || @parent_hash[key] end |
#inspect ⇒ Object
26 27 28 |
# File 'lib/active_resource/inheriting_hash.rb', line 26 def inspect to_hash.inspect end |
#pretty_print(pp) ⇒ Object
So we can see the merged object in IRB or the Rails console
22 23 24 |
# File 'lib/active_resource/inheriting_hash.rb', line 22 def pretty_print(pp) pp.pp_hash to_hash end |
#to_hash ⇒ Object
Merges the flattened parent hash (if it’s an InheritingHash) with ourself
17 18 19 |
# File 'lib/active_resource/inheriting_hash.rb', line 17 def to_hash @parent_hash.to_hash.merge(self) end |
#to_s ⇒ Object
30 31 32 |
# File 'lib/active_resource/inheriting_hash.rb', line 30 def to_s inspect end |