Method: Puppet::Parser::Scope#to_hash

Defined in:
lib/puppet/parser/scope.rb

#to_hash(recursive = true, include_undef = false) ⇒ Object

Returns a Hash containing all variables and their values, optionally (and by default) including the values defined in parent. Local values shadow parent values. Ephemeral scopes for match results ($0 - $n) are not included. Optionally include the variables that are explicitly set to undef.



676
677
678
679
680
681
682
683
684
685
686
687
688
689
# File 'lib/puppet/parser/scope.rb', line 676

def to_hash(recursive = true, include_undef = false)
  if recursive and has_enclosing_scope?
    target = enclosing_scope.to_hash(recursive)
    unless (inherited = inherited_scope).nil?
      target.merge!(inherited.to_hash(recursive))
    end
  else
    target = Hash.new
  end

  # add all local scopes
  @ephemeral.last.add_entries_to(target, include_undef)
  target
end