5 module Puppet::Parser::Functions
6 newfunction(:chop, :type => :rvalue, :doc => <<-'EOS'
7 Returns a new string with the last character removed. If the string ends
8 with `\r\n`, both characters are removed. Applying chop to an empty
9 string returns an empty string. If you wish to merely remove record
10 separators then you should use the `chomp` function.
11 Requires a string or array of strings as input.
15 raise(Puppet::ParseError, "chop(): Wrong number of arguments " +
16 "given (#{arguments.size} for 1)") if arguments.size < 1
20 unless value.is_a?(Array) || value.is_a?(String)
21 raise(Puppet::ParseError, 'chop(): Requires either an ' +
22 'array or string to work with')
26 # Numbers in Puppet are often string-encoded which is troublesome ...
27 result = value.collect { |i| i.is_a?(String) ? i.chop : i }
36 # vim: set ts=2 sw=2 et :