Update stdlib
[mirror/dsa-puppet.git] / 3rdparty / modules / stdlib / lib / puppet / parser / functions / keys.rb
1 #
2 # keys.rb
3 #
4
5 module Puppet::Parser::Functions
6   newfunction(:keys, :type => :rvalue, :doc => <<-EOS
7 Returns the keys of a hash as an array.
8     EOS
9   ) do |arguments|
10
11     raise(Puppet::ParseError, "keys(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.size < 1
12
13     hash = arguments[0]
14
15     unless hash.is_a?(Hash)
16       raise(Puppet::ParseError, 'keys(): Requires hash to work with')
17     end
18
19     result = hash.keys
20
21     return result
22   end
23 end
24
25 # vim: set ts=2 sw=2 et :