Puppet Function: array_size
- Defined in:
- lib/puppet/parser/functions/array_size.rb
- Function type:
- Ruby 3.x API
Overview
Returns the number of elements in an Array
. If a
String
is passed, simply returns 1
.
This is in contrast to the Puppet Labs stdlib
size()
function which returns the size of an
Array
or the length of a String
when called.
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/puppet/parser/functions/array_size.rb', line 2 newfunction(:array_size, :type => :rvalue, :doc => <<-'ENDHEREDOC') do |args| unless args.length == 1 Returns the number of elements in an `Array`. If a `String` is passed, simply returns `1`. This is in contrast to the Puppet Labs `stdlib` `size()` function which returns the size of an `Array` or the length of a `String` when called. @return [Integer] ENDHEREDOC raise Puppet::ParseError, ("array_size(): Exactly one argument must be passed.") end unless args[0].is_a?(Array) or args[0].is_a?(String) raise Puppet::ParseError, "array_size(): expects an Array or String, got a '#{args[0].class}'" end Array(args[0]).size end |