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


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

Returns:

  • (Boolean)

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

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

#keysObject


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_keysObject


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

alias own_keys keys

#parentObject


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

def parent
  @parent ||= {}
end