Class: Scorched::Options

Inherits:
Hash
  • Object
show all
Extended by:
DynamicDelegate
Defined in:
lib/scorched/options.rb

Instance Method Summary collapse

Methods included from DynamicDelegate

alias_each, delegate

Instance Method Details

#inspectObject



36
37
38
# File 'lib/scorched/options.rb', line 36

def inspect
  "#<#{self.class}: local#{_inspect}, merged#{to_hash.inspect}>"
end

#parent!(parent) ⇒ Object

sets parent Options object and returns self



13
14
15
16
17
# File 'lib/scorched/options.rb', line 13

def parent!(parent)
  @parent = parent
  @cache = {}
  self
end

#to_hash(inherit = true) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/scorched/options.rb', line 19

def to_hash(inherit = true)
  @cache ||= {}
  unless @cache[:self] == self
    @cache[:self] = self._to_h
    @cache[:merged] = nil
  end
  if inherit && Hash === @parent
    unless @cache[:parent] == @parent.to_hash
      @cache[:parent] = @parent.to_hash
      @cache[:merged] = nil
    end
    @cache[:merged] ||= @cache[:parent].merge(@cache[:self])
  else
    @cache[:self]
  end
end