4 module Puppet::Parser::Functions
5 newfunction(:has_key, :type => :rvalue, :doc => <<-'DOC') do |args|
7 **Deprecated:** Determine if a hash has a certain key value.
12 @example Example Usage:
14 $my_hash = {'key_one' => 'value_one'}
15 if has_key($my_hash, 'key_two') {
16 notice('we will not reach here')
18 if has_key($my_hash, 'key_one') {
19 notice('this will be printed')
22 > **Note:** **Deprecated** since Puppet 4.0.0, this can now be achieved in the Puppet
23 language with the following equivalent expression:
24 $my_hash = {'key_one' => 'value_one'}
25 if 'key_one' in $my_hash {
26 notice('this will be printed')
31 unless args.length == 2
32 raise Puppet::ParseError, "has_key(): wrong number of arguments (#{args.length}; must be 2)"
34 unless args[0].is_a?(Hash)
35 raise Puppet::ParseError, "has_key(): expects the first argument to be a hash, got #{args[0].inspect} which is of type #{args[0].class}"