X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=3rdparty%2Fmodules%2Fstdlib%2Flib%2Fpuppet%2Fparser%2Ffunctions%2Fdelete_values.rb;h=f1625228ada151062a004fe4fb2f5a1a816ef88e;hb=30caaa85aed7015ca0d77216bff175eebd917eb7;hp=e799aef0ee6d56e49b998b6e86ef9ec717d9ef85;hpb=6963202b4b62c2816655ac9532521b018fdf83bd;p=mirror%2Fdsa-puppet.git diff --git a/3rdparty/modules/stdlib/lib/puppet/parser/functions/delete_values.rb b/3rdparty/modules/stdlib/lib/puppet/parser/functions/delete_values.rb index e799aef0e..f1625228a 100644 --- a/3rdparty/modules/stdlib/lib/puppet/parser/functions/delete_values.rb +++ b/3rdparty/modules/stdlib/lib/puppet/parser/functions/delete_values.rb @@ -1,23 +1,33 @@ +# +# delete_values.rb +# module Puppet::Parser::Functions - newfunction(:delete_values, :type => :rvalue, :doc => <<-EOS -Deletes all instances of a given value from a hash. + newfunction(:delete_values, :type => :rvalue, :doc => <<-DOC + @summary + Deletes all instances of a given value from a hash. -*Examples:* + @example Example usage - delete_values({'a'=>'A','b'=>'B','c'=>'C','B'=>'D'}, 'B') + delete_values({'a'=>'A','b'=>'B','c'=>'C','B'=>'D'}, 'B') + Would return: {'a'=>'A','c'=>'C','B'=>'D'} -Would return: {'a'=>'A','c'=>'C','B'=>'D'} + > *Note:* + Since Puppet 4.0.0 the equivalent can be performed with the + built-in [`filter`](https://puppet.com/docs/puppet/latest/function.html#filter) function: + $array.filter |$val| { $val != 'B' } + $hash.filter |$key, $val| { $val != 'B' } - EOS - ) do |arguments| + @return [Hash] The given hash now missing all instances of the targeted value + DOC + ) do |arguments| raise(Puppet::ParseError, "delete_values(): Wrong number of arguments given (#{arguments.size} of 2)") if arguments.size != 2 hash, item = arguments - if not hash.is_a?(Hash) + unless hash.is_a?(Hash) raise(TypeError, "delete_values(): First argument must be a Hash. Given an argument of class #{hash.class}.") end - hash.dup.delete_if { |key, val| item == val } + hash.dup.delete_if { |_key, val| item == val } end end