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.



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

Returns:

  • (Boolean)


20
21
22
# File 'lib/rouge/util.rb', line 20

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

#keysObject



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_keysObject



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

alias own_keys keys

#parentObject



16
17
18
# File 'lib/rouge/util.rb', line 16

def parent
  @parent ||= {}
end