Puppet Function: type_of

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

Overview

type_of(Any $value)Any

Returns the type when passed a value.

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.

The built-in type() function in puppet is generally preferred over this function this function is provided for backwards compatibility.

Examples:

how to compare values' types

# compare the types of two values
if type_of($first_value) != type_of($second_value) { fail("first_value and second_value are different types") }

how to compare against an abstract type

unless type_of($first_value) <= Numeric { fail("first_value must be Numeric") }
unless type_of{$first_value) <= Collection[1] { fail("first_value must be an Array or Hash, and contain at least one element") }

Parameters:

  • value (Any)

Returns:

  • (Any)


15
16
17
18
19
# File 'modules/stdlib/lib/puppet/functions/type_of.rb', line 15

Puppet::Functions.create_function(:type_of) do
  def type_of(value)
    Puppet::Pops::Types::TypeCalculator.infer_set(value)
  end
end