length.rb 498 B

1234567891011121314
  1. # A function to eventually replace the old size() function for stdlib - The original size function did not handle Puppets new type capabilities, so this function is a Puppet 4 compatible solution.
  2. Puppet::Functions.create_function(:length) do
  3. dispatch :length do
  4. param 'Variant[String,Array,Hash]', :value
  5. end
  6. def length(value)
  7. if value.is_a?(String)
  8. result = value.length
  9. elsif value.is_a?(Array) || value.is_a?(Hash)
  10. result = value.size
  11. end
  12. result
  13. end
  14. end