Sha256: 1499a8ffc630a77ec1e7d1cf8e1fe73ff0884125061ba412df2a7a90424d3c0b
Contents?: true
Size: 663 Bytes
Versions: 7
Compression:
Stored size: 663 Bytes
Contents
# # flatten.rb # module Puppet::Parser::Functions newfunction(:flatten, :type => :rvalue, :doc => <<-EOS This function flattens any deeply nested arrays and returns a single flat array as a result. *Examples:* flatten(['a', ['b', ['c']]]) Would return: ['a','b','c'] EOS ) do |arguments| raise(Puppet::ParseError, "flatten(): Wrong number of arguments " + "given (#{arguments.size} for 1)") if arguments.size < 1 array = arguments[0] unless array.is_a?(Array) raise(Puppet::ParseError, 'flatten(): Requires array to work with') end result = array.flatten return result end end # vim: set ts=2 sw=2 et :
Version data entries
7 entries across 7 versions & 1 rubygems