1 module Puppet::Parser::Functions
2 newfunction(:count, :type => :rvalue, :arity => -2, :doc => <<-EOS
3 Takes an array as first argument and an optional second argument.
4 Count the number of elements in array that matches second argument.
5 If called with only an array it counts the number of elements that are not nil/undef.
9 if (args.size > 2) then
10 raise(ArgumentError, "count(): Wrong number of arguments "+
11 "given #{args.size} for 1 or 2.")
14 collection, item = args
19 collection.count { |obj| obj != nil && obj != :undef && obj != '' }