From: Krzysztof Wilczynski Date: Fri, 29 Apr 2011 23:57:24 +0000 (+0100) Subject: Moved to unless from if not for code clarity and changed wording X-Git-Url: https://gitweb.fluxo.info/?a=commitdiff_plain;h=555c50d73595478a8a422b83d073514f7dbed0f0;p=puppet-stdlib.git Moved to unless from if not for code clarity and changed wording of few error messages. Signed-off-by: Krzysztof Wilczynski --- diff --git a/delete_at.rb b/delete_at.rb index 1869476..10190ba 100644 --- a/delete_at.rb +++ b/delete_at.rb @@ -12,25 +12,25 @@ module Puppet::Parser::Functions array = arguments[0] - if not array.is_a?(Array) - raise(Puppet::ParseError, 'delete_at(): Requires an array to work with') + unless array.is_a?(Array) + raise(Puppet::ParseError, 'delete_at(): Requires array to work with') end index = arguments[1] if index.is_a?(String) and not index.match(/^\d+$/) raise(Puppet::ParseError, 'delete_at(): You must provide ' + - 'positive numeric index') + 'non-negative numeric index') end result = array.clone - # In Puppet numbers are often string-encoded ... + # Numbers in Puppet are often string-encoded which is troublesome ... index = index.to_i if index > result.size - 1 # First element is at index 0 is it not? raise(Puppet::ParseError, 'delete_at(): Given index ' + - 'exceeds array size') + 'exceeds size of array given') end result.delete_at(index) # We ignore the element that got deleted ...