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.



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

Returns:

  • (Boolean)


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

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

#keysObject



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_keysObject



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

alias own_keys keys

#parentObject



24
25
26
# File 'lib/rouge/util.rb', line 24

def parent
  @parent ||= {}
end