diff modules/stdlib/lib/puppet/parser/functions/any2array.rb @ 275:d9352a684e62

Mass update of modules to remove deprecation warnings
author IBBoard <dev@ibboard.co.uk>
date Sun, 26 Jan 2020 11:36:07 +0000
parents c42fb28cff86
children adf6fe9bbc17
line wrap: on
line diff
--- a/modules/stdlib/lib/puppet/parser/functions/any2array.rb	Sat Jan 04 11:42:45 2020 +0000
+++ b/modules/stdlib/lib/puppet/parser/functions/any2array.rb	Sun Jan 26 11:36:07 2020 +0000
@@ -3,9 +3,35 @@
 #
 module Puppet::Parser::Functions
   newfunction(:any2array, :type => :rvalue, :doc => <<-DOC
-    This converts any object to an array containing that object. Empty argument
-    lists are converted to an empty array. Arrays are left untouched. Hashes are
-    converted to arrays of alternating keys and values.
+    @summary
+      This converts any object to an array containing that object.
+
+    Empty argument lists are converted to an empty array. Arrays are left
+    untouched. Hashes are converted to arrays of alternating keys and values.
+
+    > *Note:*
+      since Puppet 5.0.0 it is possible to create new data types for almost any
+      datatype using the type system and the built-in
+      [`Array.new`](https://puppet.com/docs/puppet/latest/function.html#conversion-to-array-and-tuple)
+      function is used to create a new Array..
+
+      ```
+      $hsh = {'key' => 42, 'another-key' => 100}
+      notice(Array($hsh))
+      ```
+
+    Would notice `[['key', 42], ['another-key', 100]]`
+
+    The Array data type also has a special mode to "create an array if not already an array"
+
+      ```
+      notice(Array({'key' => 42, 'another-key' => 100}, true))
+      ```
+
+    Would notice `[{'key' => 42, 'another-key' => 100}]`, as the `true` flag prevents the hash from being
+    transformed into an array.
+
+    @return [Array] The new array containing the given object
   DOC
              ) do |arguments|
 
@@ -15,6 +41,7 @@
 
     return arguments unless arguments.length == 1
     return arguments[0] if arguments[0].is_a?(Array)
+    return [] if arguments == ['']
     if arguments[0].is_a?(Hash)
       result = []
       arguments[0].each do |key, value|