Puppet Function: to_string

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

Overview

to_string(Any $input)Any

Converts the argument into a String.

Only works if the passed argument responds to the to_s() Ruby method.

Parameters:

  • input (Any)

    The argument to convert into a String

Returns:

  • (Any)


2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/puppet/parser/functions/to_string.rb', line 2

newfunction(:to_string, :type => :rvalue, :arity => 1, :doc => <<-EOS) do |arguments|

  arg = arguments[0]
  Converts the argument into a `String`.

  Only works if the passed argument responds to the `to_s()` Ruby method.

  @param input [Any]
    The argument to convert into a `String`

  @return [String]
  EOS

  return arg if arg.is_a?(String)

  if arg.respond_to?(:to_s)
    return arg.to_s
  else
    raise(Puppet::ParseError, "to_string(): Object type '#{arg.class}' cannot be converted to a String")
  end
end