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