Skip to content

Instantly share code, notes, and snippets.

@richardc
Last active December 19, 2015 18:38
Show Gist options
  • Select an option

  • Save richardc/6000050 to your computer and use it in GitHub Desktop.

Select an option

Save richardc/6000050 to your computer and use it in GitHub Desktop.
#
# concat.rb
#
module Puppet::Parser::Functions
newfunction(:append, :type => :lvalue, :doc => <<-EOS
Appends the contents of array 2 onto array 1.
*Example:*
$foo = [ '1', '2', '3' ]
append($foo, ['4','5','6'])
Would result in $foo having the value:
['1','2','3','4','5','6']
EOS
) do |arguments|
# Check that 2 arguments have been given ...
raise(Puppet::ParseError, "append(): Wrong number of arguments " +
"given (#{arguments.size} for 2)") if arguments.size != 2
a = arguments[0]
b = arguments[1]
# Check that both args are arrays.
unless a.is_a?(Array) and b.is_a?(Array)
raise(Puppet::ParseError, 'append(): Requires arrays to work with')
end
a.concat(b)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment