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 given (#{arguments.size} for 1)") if arguments.size < 1
19 unless value.is_a?(Array) || value.is_a?(String)
20 raise(Puppet::ParseError, 'chop(): Requires either an array or string to work with')
24 # Numbers in Puppet are often string-encoded which is troublesome ...
25 result = value.collect { |i| i.is_a?(String) ? i.chop : i }
34 # vim: set ts=2 sw=2 et :