diff options
-rw-r--r-- | delete_at.rb | 10 |
1 files changed, 5 insertions, 5 deletions
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 ... |