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.
3 4 5 |
# File 'lib/rouge/util.rb', line 3 def initialize(parent=nil) @parent = parent end |
Instance Method Details
#[](k) ⇒ Object
7 8 9 10 11 12 |
# File 'lib/rouge/util.rb', line 7 def [](k) _sup = super return _sup if own_keys.include?(k) _sup || parent[k] end |
#each(&b) ⇒ Object
22 23 24 25 26 |
# File 'lib/rouge/util.rb', line 22 def each(&b) keys.each do |k| b.call(k, self[k]) end end |
#include?(k) ⇒ Boolean
18 19 20 |
# File 'lib/rouge/util.rb', line 18 def include?(k) super or parent.include?(k) end |
#keys ⇒ Object
29 30 31 32 33 |
# File 'lib/rouge/util.rb', line 29 def keys keys = own_keys.concat(parent.keys) keys.uniq! keys end |
#own_keys ⇒ Object
28 |
# File 'lib/rouge/util.rb', line 28 alias own_keys keys |
#parent ⇒ Object
14 15 16 |
# File 'lib/rouge/util.rb', line 14 def parent @parent ||= {} end |