Puppet Function: num2str

Defined in:
lib/puppet/parser/functions/num2str.rb
Function type:
Ruby 3.x API

Overview

num2str()Any

Convert numbers to strings.

Returns:

  • (Any)


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/puppet/parser/functions/num2str.rb', line 5

newfunction(:num2str, :type => :rvalue, :doc => <<-EOS
Convert numbers to strings.
EOS
) do |arguments|
  raise(Puppet::ParseError, "num2str(): Wrong number of arguments " +
    "given (#{arguments.size} for 1)") if arguments.size < 1

  num = arguments[0]

  return num if num.is_a?(String) and num =~ /^-?[0-9]+(?:\.[0-9]+)?$/
  raise(Puppet::ParseError, "num2str(): value #{num} is not a number and " +
    " appears to be a #{num.class}.") unless num.is_a?(Numeric)

  return num.to_s
end