]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/stdlib/lib/puppet/functions/type_of.rb
upgrade to stdlib 4.6.1
[dsa-puppet.git] / 3rdparty / modules / stdlib / lib / puppet / functions / type_of.rb
1 # Returns the type when passed a value.
2 #
3 # @example how to compare values' types
4 #   # compare the types of two values
5 #   if type_of($first_value) != type_of($second_value) { fail("first_value and second_value are different types") }
6 # @example how to compare against an abstract type
7 #   unless type_of($first_value) <= Numeric { fail("first_value must be Numeric") }
8 #   unless type_of{$first_value) <= Collection[1] { fail("first_value must be an Array or Hash, and contain at least one element") }
9 #
10 # See the documentation for "The Puppet Type System" for more information about types.
11 # See the `assert_type()` function for flexible ways to assert the type of a value.
12 #
13 Puppet::Functions.create_function(:type_of) do
14   def type_of(value)
15     Puppet::Pops::Types::TypeCalculator.infer_set(value)
16   end
17 end