Class: Rouge::InheritableHash
- Inherits:
-
Hash
- Object
- Hash
- Rouge::InheritableHash
- Defined in:
- lib/rouge/util.rb
Instance Method Summary collapse
- #[](k) ⇒ Object
- #each(&b) ⇒ Object
- #include?(k) ⇒ Boolean
-
#initialize(parent = nil) ⇒ InheritableHash
constructor
A new instance of InheritableHash.
- #keys ⇒ Object
- #own_keys ⇒ Object
- #parent ⇒ Object
Constructor Details
#initialize(parent = nil) ⇒ InheritableHash
Returns a new instance of InheritableHash.
5 6 7 |
# File 'lib/rouge/util.rb', line 5 def initialize(parent=nil) @parent = parent end |
Instance Method Details
#[](k) ⇒ Object
9 10 11 12 13 14 |
# File 'lib/rouge/util.rb', line 9 def [](k) _sup = super return _sup if own_keys.include?(k) _sup || parent[k] end |
#each(&b) ⇒ Object
24 25 26 27 28 |
# File 'lib/rouge/util.rb', line 24 def each(&b) keys.each do |k| b.call(k, self[k]) end end |
#include?(k) ⇒ Boolean
20 21 22 |
# File 'lib/rouge/util.rb', line 20 def include?(k) super or parent.include?(k) end |
#keys ⇒ Object
31 32 33 34 35 |
# File 'lib/rouge/util.rb', line 31 def keys keys = own_keys.concat(parent.keys) keys.uniq! keys end |
#own_keys ⇒ Object
30 |
# File 'lib/rouge/util.rb', line 30 alias own_keys keys |
#parent ⇒ Object
16 17 18 |
# File 'lib/rouge/util.rb', line 16 def parent @parent ||= {} end |