Puppet Function: is_a

Defined in:
modules/stdlib/lib/puppet/functions/is_a.rb
Function type:
Ruby 4.x API

Overview

is_a(Any $value, Type $type)Boolean

See the documentation for “The Puppet Type System” for more information about types. See the `assert_type()` function for flexible ways to assert the type of a value.

Examples:

Example Usage:

# check a data type
  foo = 3
  $bar = [1,2,3]
  $baz = 'A string!'

  if $foo.is_a(Integer) {
    notify  { 'foo!': }
  }
  if $bar.is_a(Array) {
    notify { 'bar!': }
  }
  if $baz.is_a(String) {
    notify { 'baz!': }
  }

Parameters:

  • value (Any)

    The value to be checked

  • type (Type)

    The expected type

Returns:

  • (Boolean)

    Return's `true` or `false`.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'modules/stdlib/lib/puppet/functions/is_a.rb', line 24

Puppet::Functions.create_function(:is_a) do
  # @param value
  #   The value to be checked
  #
  # @param type
  #   The expected type
  #
  # @return [Boolean]
  #   Return's `true` or `false`.
  dispatch :is_a do
    param 'Any', :value
    param 'Type', :type
  end

  def is_a(value, type) # rubocop:disable Style/PredicateName : Used in to many other places to rename at this time, attempting to refactor caused Rubocop to crash.
    # See puppet's lib/puppet/pops/evaluator/evaluator_impl.rb eval_MatchExpression
    Puppet::Pops::Types::TypeCalculator.instance?(type, value)
  end
end