Suggest different variables to use if we want to tunnel both v4 and v6
[mirror/dsa-puppet.git] / 3rdparty / modules / stdlib / lib / puppet / functions / length.rb
1 # A function to eventually replace the old size() function for stdlib
2 # The original size function did not handle Puppets new type capabilities, so this function is a Puppet 4 compatible solution.
3 #
4 # Note: from Puppet 6.0.0, the compatible function with the same name in Puppet core
5 # will be used instead of this function.
6 #
7 Puppet::Functions.create_function(:length) do
8   dispatch :length do
9     param 'Variant[String,Array,Hash]', :value
10   end
11   def length(value)
12     if value.is_a?(String)
13       result = value.length
14     elsif value.is_a?(Array) || value.is_a?(Hash)
15       result = value.size
16     end
17     result
18   end
19 end