Skip to content

Instantly share code, notes, and snippets.

@duritong
Created October 27, 2010 21:23
Show Gist options
  • Save duritong/650043 to your computer and use it in GitHub Desktop.
Save duritong/650043 to your computer and use it in GitHub Desktop.
$ facter | grep puppet
puppetversion => 2.6.1
$ cat lib/puppet/parser/functions/array_del.rb
Puppet::Parser::Functions::newfunction(
:array_del,
:type => :rvalue,
:doc => "Deletes items from an array
Example: array_del(['a','b'],'b') -> ['a']"
) do |args|
raise Puppet::ParseError, 'array_del() needs two arguments' if args.length != 2
args[0].to_a.delete(args[1])
args[0]
end
$ cat test.pp
$a = ['a','b','c']
$b = array_del($a,'b')
notice $b
notice $a
$ RUBYLIB=lib/ puppet test.pp
notice: Scope(Class[main]): a c
notice: Scope(Class[main]): a c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment