Last active
December 19, 2015 18:38
-
-
Save richardc/6000050 to your computer and use it in GitHub Desktop.
a fork of https://github.com/puppetlabs/puppetlabs-stdlib/blob/master/lib/puppet/parser/functions/concat.rb making the append behaviour more explicit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # | |
| # 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