Puppet Function: stdlib::start_with

Defined in:
vendor_modules/stdlib/lib/puppet/functions/stdlib/start_with.rb
Function type:
Ruby 4.x API

Summary

Returns true if str starts with one of the prefixes given. Each of the prefixes should be a String.

Overview

stdlib::start_with(String $test_string, Variant[String[1],Array[String[1], 1]] $prefixes)Boolean

Examples:

'foobar'.stdlib::start_with('foo') => true
'foobar'.stdlib::start_with('bar') => false
'foObar'.stdlib::start_with(['bar', 'baz']) => false

Parameters:

  • test_string (String)

    The string to check

  • prefixes (Variant[String[1],Array[String[1], 1]])

    The prefixes to check.

Returns:

  • (Boolean)

    True or False



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'vendor_modules/stdlib/lib/puppet/functions/stdlib/start_with.rb', line 6

Puppet::Functions.create_function(:'stdlib::start_with') do
  # @param test_string The string to check
  # @param prefixes The prefixes to check.
  # @example
  #   'foobar'.stdlib::start_with('foo') => true
  #   'foobar'.stdlib::start_with('bar') => false
  #   'foObar'.stdlib::start_with(['bar', 'baz']) => false
  # @return [Boolean] True or False
  dispatch :start_with do
    param 'String', :test_string
    param 'Variant[String[1],Array[String[1], 1]]', :prefixes
    return_type 'Boolean'
  end

  def start_with(test_string, prefixes)
    test_string.start_with?(*prefixes)
  end
end