File: start_with.rb

package info (click to toggle)
puppet-module-puppetlabs-stdlib 9.4.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,448 kB
  • sloc: ruby: 3,522; sh: 46; makefile: 2
file content (23 lines) | stat: -rw-r--r-- 744 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# frozen_string_literal: true

# @summary
#   Returns true if str starts with one of the prefixes given. Each of the prefixes should be a String.
#
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