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%2Fcount.rb;h=c302aa1960b176df06d81e350ce2513530ef06ed;hp=71999a8cf891ad871d5181b587e820e65c0db5b6;hb=30caaa85aed7015ca0d77216bff175eebd917eb7;hpb=6f656bd4265e3dab13b9af2bf96e9044322e9d8f diff --git a/3rdparty/modules/stdlib/lib/puppet/parser/functions/count.rb b/3rdparty/modules/stdlib/lib/puppet/parser/functions/count.rb index 71999a8cf..c302aa196 100644 --- a/3rdparty/modules/stdlib/lib/puppet/parser/functions/count.rb +++ b/3rdparty/modules/stdlib/lib/puppet/parser/functions/count.rb @@ -3,21 +3,26 @@ # module Puppet::Parser::Functions newfunction(:count, :type => :rvalue, :arity => -2, :doc => <<-DOC - Takes an array as first argument and an optional second argument. - Count the number of elements in array that is equal to the second argument. + @summary + Counts the number of elements in array. + + Takes an array as first argument and an optional second argument. Counts the number of elements in array that is equal to the second argument. If called with only an array, it counts the number of elements that are not nil/undef/empty-string. - Note: equality is tested with a Ruby method and it is therefore subject to what Ruby considers - to be equal. For strings this means that equality is case sensitive. + > *Note:* + equality is tested with a Ruby method and it is therefore subject to what Ruby considers + to be equal. For strings this means that equality is case sensitive. In Puppet core, counting can be done in general by using a combination of the core functions filter() (since Puppet 4.0.0) and length() (since Puppet 5.5.0, before that in stdlib). + Example below shows counting values that are not undef. - notice([42, "hello", undef].filter |$x| { $x =~ NotUndef }.length) + ```notice([42, "hello", undef].filter |$x| { $x =~ NotUndef }.length)``` Would notice the value 2. + @return [Integer] The amount of elements counted within the array DOC ) do |args|