Class: Rouge::InheritableHash

Inherits:
Hash
  • Object
show all
Defined in:
lib/rouge/util.rb

Instance Method Summary collapse

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

Returns:

  • (Boolean)

18
19
20
# File 'lib/rouge/util.rb', line 18

def include?(k)
  super or parent.include?(k)
end

#keysObject


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_keysObject


28
# File 'lib/rouge/util.rb', line 28

alias own_keys keys

#parentObject


14
15
16
# File 'lib/rouge/util.rb', line 14

def parent
  @parent ||= {}
end