summaryrefslogtreecommitdiff
path: root/lib/puppet/parser/functions/delete.rb
diff options
context:
space:
mode:
authorBryan Jen <bryan.jen@gmail.com>2016-05-04 09:13:20 -0700
committerBryan Jen <bryan.jen@gmail.com>2016-05-04 09:13:20 -0700
commitf46c9fdbcee687325be372e3650f05af5d4a66c6 (patch)
treebaa574d4e850aec389288bc943368bfb8de3dfe9 /lib/puppet/parser/functions/delete.rb
parentf48747b8af8fdad455cfd5b5d0d2c2abfd8c9415 (diff)
parent540546b9b41745bbc4821f9966ae301dc0b5056a (diff)
Merge pull request #592 from jyaworski/fix_delete
Use reject instead of delete_if
Diffstat (limited to 'lib/puppet/parser/functions/delete.rb')
-rw-r--r--lib/puppet/parser/functions/delete.rb16
1 files changed, 9 insertions, 7 deletions
diff --git a/lib/puppet/parser/functions/delete.rb b/lib/puppet/parser/functions/delete.rb
index f548b44..814e1ad 100644
--- a/lib/puppet/parser/functions/delete.rb
+++ b/lib/puppet/parser/functions/delete.rb
@@ -2,8 +2,6 @@
# delete.rb
#
-# TODO(Krzysztof Wilczynski): We need to add support for regular expression ...
-
module Puppet::Parser::Functions
newfunction(:delete, :type => :rvalue, :doc => <<-EOS
Deletes all instances of a given element from an array, substring from a
@@ -22,19 +20,23 @@ string, or key from a hash.
delete('abracadabra', 'bra')
Would return: 'acada'
+
+ delete(['abracadabra'], '^.*bra.*$')
+ Would return: []
+
+ delete(['abracadabra'], '^.*jimbob.*$')
+ Would return: ['abracadabra']
EOS
) do |arguments|
- if (arguments.size != 2) then
- raise(Puppet::ParseError, "delete(): Wrong number of arguments "+
- "given #{arguments.size} for 2.")
- end
+ raise(Puppet::ParseError, "delete(): Wrong number of arguments "+
+ "given #{arguments.size} for 2") unless arguments.size == 2
collection = arguments[0].dup
Array(arguments[1]).each do |item|
case collection
when Array, Hash
- collection.delete item
+ collection.reject! { |coll_item| (coll_item =~ %r{\b#{item}\b}) }
when String
collection.gsub! item, ''
else