X-Git-Url: https://git.adam-barratt.org.uk/?p=mirror%2Fdsa-puppet.git;a=blobdiff_plain;f=3rdparty%2Fmodules%2Fstdlib%2Flib%2Fpuppet%2Fparser%2Ffunctions%2Fdelete_at.rb;h=992d7d8d6d77410812c741939c41c66291f5b476;hp=0a1a9400b16f681f346d26f7c7f2ca66db6dd61b;hb=30caaa85aed7015ca0d77216bff175eebd917eb7;hpb=6f656bd4265e3dab13b9af2bf96e9044322e9d8f diff --git a/3rdparty/modules/stdlib/lib/puppet/parser/functions/delete_at.rb b/3rdparty/modules/stdlib/lib/puppet/parser/functions/delete_at.rb index 0a1a9400b..992d7d8d6 100644 --- a/3rdparty/modules/stdlib/lib/puppet/parser/functions/delete_at.rb +++ b/3rdparty/modules/stdlib/lib/puppet/parser/functions/delete_at.rb @@ -2,27 +2,32 @@ # delete_at.rb # module Puppet::Parser::Functions - newfunction(:delete_at, :type => :rvalue, :doc => <<-DOC - Deletes a determined indexed value from an array. + newfunction(:delete_at, :type => :rvalue, :doc => <<-DOC) do |arguments| + @summary + Deletes a determined indexed value from an array. - *Examples:* + For example + ```delete_at(['a','b','c'], 1)``` - delete_at(['a','b','c'], 1) + Would return: `['a','c']` - Would return: ['a','c'] + > *Note:* + Since Puppet 4 this can be done in general with the built-in + [`filter`](https://puppet.com/docs/puppet/latest/function.html#filter) function: - Note that since Puppet 4 this can be done in general with the filter function: - - ['a', 'b', 'c'].filter |$pos, $val | { $pos != 1 } + ```['a', 'b', 'c'].filter |$pos, $val | { $pos != 1 }``` Or if a delete is wanted from the beginning or end of the array, by using the slice operator [ ]: + ``` + $array[0, -1] # the same as all the values + $array[2, -1] # all but the first 2 elements + $array[0, -3] # all but the last 2 elements + $array[1, -2] # all but the first and last element + ``` + + @return [Array] The given array, now missing the target value - $array[0, -1] # the same as all the values - $array[2, -1] # all but the first 2 elements - $array[0, -3] # all but the last 2 elements - $array[1, -2] # all but the first and last element DOC - ) do |arguments| raise(Puppet::ParseError, "delete_at(): Wrong number of arguments given (#{arguments.size} for 2)") if arguments.size < 2