Update stdlib and concat to 6.1.0 both
[mirror/dsa-puppet.git] / 3rdparty / modules / stdlib / lib / puppet / functions / type_of.rb
1 # @summary
2 #   Returns the type of the passed value.
3 #
4 # @example how to compare values' types
5 #   # compare the types of two values
6 #   if type_of($first_value) != type_of($second_value) { fail("first_value and second_value are different types") }
7 # @example how to compare against an abstract type
8 #   unless type_of($first_value) <= Numeric { fail("first_value must be Numeric") }
9 #   unless type_of{$first_value) <= Collection[1] { fail("first_value must be an Array or Hash, and contain at least one element") }
10 #
11 # See the documentation for "The Puppet Type System" for more information about types.
12 # See the `assert_type()` function for flexible ways to assert the type of a value.
13 #
14 # The built-in type() function in puppet is generally preferred over this function
15 # this function is provided for backwards compatibility.
16 Puppet::Functions.create_function(:type_of) do
17   # @return [String]
18   #   the type of the passed value
19   #
20   # @param value
21   def type_of(value)
22     Puppet::Pops::Types::TypeCalculator.infer_set(value)
23   end
24 end