From 5c79107863a42a9d347637146f0c0f728f9b92ad Mon Sep 17 00:00:00 2001 From: gcmalloc Date: Tue, 21 Jul 2015 19:25:27 +0200 Subject: adding support for hash in the size function --- lib/puppet/parser/functions/size.rb | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'lib/puppet/parser/functions/size.rb') diff --git a/lib/puppet/parser/functions/size.rb b/lib/puppet/parser/functions/size.rb index cc207e3..0d6cc96 100644 --- a/lib/puppet/parser/functions/size.rb +++ b/lib/puppet/parser/functions/size.rb @@ -2,11 +2,9 @@ # size.rb # -# TODO(Krzysztof Wilczynski): Support for hashes would be nice too ... - module Puppet::Parser::Functions newfunction(:size, :type => :rvalue, :doc => <<-EOS -Returns the number of elements in a string or array. +Returns the number of elements in a string, an array or a hash EOS ) do |arguments| @@ -29,13 +27,13 @@ Returns the number of elements in a string or array. Float(item) raise(Puppet::ParseError, 'size(): Requires either ' + - 'string or array to work with') + 'string, array or hash to work with') rescue ArgumentError result = item.size end - elsif item.is_a?(Array) + elsif item.is_a?(Array) || item.is_a?(Hash) result = item.size else raise(Puppet::ParseError, 'size(): Unknown type given') -- cgit v1.2.3