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.
13 14 15 |
# File 'lib/rouge/util.rb', line 13 def initialize(parent=nil) @parent = parent end |
Instance Method Details
#[](k) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/rouge/util.rb', line 17 def [](k) _sup = super return _sup if own_keys.include?(k) _sup || parent[k] end |
#each(&b) ⇒ Object
32 33 34 35 36 |
# File 'lib/rouge/util.rb', line 32 def each(&b) keys.each do |k| b.call(k, self[k]) end end |
#include?(k) ⇒ Boolean
28 29 30 |
# File 'lib/rouge/util.rb', line 28 def include?(k) super or parent.include?(k) end |
#keys ⇒ Object
39 40 41 42 43 |
# File 'lib/rouge/util.rb', line 39 def keys keys = own_keys.concat(parent.keys) keys.uniq! keys end |
#own_keys ⇒ Object
38 |
# File 'lib/rouge/util.rb', line 38 alias own_keys keys |
#parent ⇒ Object
24 25 26 |
# File 'lib/rouge/util.rb', line 24 def parent @parent ||= {} end |