1 module Puppet::Parser::Functions
3 newfunction(:has_key, :type => :rvalue, :doc => <<-'ENDHEREDOC') do |args|
4 Determine if a hash has a certain key value.
8 $my_hash = {'key_one' => 'value_one'}
9 if has_key($my_hash, 'key_two') {
10 notice('we will not reach here')
12 if has_key($my_hash, 'key_one') {
13 notice('this will be printed')
18 unless args.length == 2
19 raise Puppet::ParseError, ("has_key(): wrong number of arguments (#{args.length}; must be 2)")
21 unless args[0].is_a?(Hash)
22 raise Puppet::ParseError, "has_key(): expects the first argument to be a hash, got #{args[0].inspect} which is of type #{args[0].class}"
24 args[0].has_key?(args[1])