diff options
author | gcmalloc <gcmalloc@gmail.com> | 2015-07-21 19:25:27 +0200 |
---|---|---|
committer | gcmalloc <gcmalloc@gmail.com> | 2015-07-22 12:11:52 +0200 |
commit | 5c79107863a42a9d347637146f0c0f728f9b92ad (patch) | |
tree | 20b289ee8fce9b39285cbd94bc890b980a14dc94 /lib/puppet/parser/functions | |
parent | dde8aa095af5c7caa28c8dd0aa9ea31565482317 (diff) |
adding support for hash in the size function
Diffstat (limited to 'lib/puppet/parser/functions')
-rw-r--r-- | lib/puppet/parser/functions/size.rb | 8 |
1 files changed, 3 insertions, 5 deletions
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') |