X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=3rdparty%2Fmodules%2Fstdlib%2Flib%2Fpuppet%2Fparser%2Ffunctions%2Fabs.rb;h=59e468e982c086346b9c81d20623a88c67c12aca;hb=131e09855e065be940e104d9ab0f18940cc76257;hp=222a902ee978b0544087e2035ea5aaf542e7979c;hpb=407d322498f4fde815abf381007fbecfe5c10b2b;p=mirror%2Fdsa-puppet.git diff --git a/3rdparty/modules/stdlib/lib/puppet/parser/functions/abs.rb b/3rdparty/modules/stdlib/lib/puppet/parser/functions/abs.rb index 222a902ee..59e468e98 100644 --- a/3rdparty/modules/stdlib/lib/puppet/parser/functions/abs.rb +++ b/3rdparty/modules/stdlib/lib/puppet/parser/functions/abs.rb @@ -1,23 +1,25 @@ # # abs.rb # - module Puppet::Parser::Functions - newfunction(:abs, :type => :rvalue, :doc => <<-EOS + newfunction(:abs, :type => :rvalue, :doc => <<-DOC Returns the absolute value of a number, for example -34.56 becomes 34.56. Takes a single integer and float value as an argument. - EOS - ) do |arguments| - raise(Puppet::ParseError, "abs(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.size < 1 + Note: from Puppet 6.0.0, the compatible function with the same name in Puppet core + will be used instead of this function. + DOC + ) do |arguments| + + raise(Puppet::ParseError, "abs(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty? value = arguments[0] # Numbers in Puppet are often string-encoded which is troublesome ... if value.is_a?(String) - if value.match(/^-?(?:\d+)(?:\.\d+){1}$/) + if value =~ %r{^-?(?:\d+)(?:\.\d+){1}$} value = value.to_f - elsif value.match(/^-?\d+$/) + elsif value =~ %r{^-?\d+$} value = value.to_i else raise(Puppet::ParseError, 'abs(): Requires float or integer to work with')