Puppet Function: simplib::to_string

Defined in:
lib/puppet/functions/simplib/to_string.rb
Function type:
Ruby 4.x API

Overview

simplib::to_string(Any $input)String

Converts the argument into a ‘String`.

Parameters:

  • input (Any)

    The argument to convert into a ‘String`

Returns:

  • (String)

    Converted input



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

Puppet::Functions.create_function(:'simplib::to_string') do

  # @param input The argument to convert into a `String`
  # @return [String] Converted input
  dispatch :to_string do
    required_param 'Any', :input
  end

  def to_string(input)
    return input if input.is_a?(String)

    if input.respond_to?(:to_s)
      return input.to_s
    else
      # Should not be able to get here with Puppet, especially since
      # Ruby provides a `to_s()` method for all objects
      fail("simplib::to_string(): Object type '#{input.class}' cannot be converted to a String")
    end
  end
end