Puppet Function: :'stdlib::extname'

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

Overview

:'stdlib::extname'(String $filename)String

If Path is a Dotfile, or starts with a Period, then the starting Dot is not dealt with the Start of the Extension.

An empty String will also be returned, when the Period is the last Character in Path.

Examples:

Determining the Extension of a Filename

stdlib::extname('test.rb')       => '.rb'
stdlib::extname('a/b/d/test.rb') => '.rb'
stdlib::extname('test')          => ''
stdlib::extname('.profile')      => ''

Parameters:

  • filename (String)

    The Filename

Returns:

  • (String)

    The Extension starting from the last Period



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'modules/stdlib/lib/puppet/functions/stdlib/extname.rb', line 10

Puppet::Functions.create_function(:'stdlib::extname') do
  # @param filename The Filename
  # @return [String] The Extension starting from the last Period
  # @example Determining the Extension of a Filename
  #   stdlib::extname('test.rb')       => '.rb'
  #   stdlib::extname('a/b/d/test.rb') => '.rb'
  #   stdlib::extname('test')          => ''
  #   stdlib::extname('.profile')      => ''
  dispatch :extname do
    param 'String', :filename
    return_type 'String'
  end

  def extname(filename)
    File.extname(filename)
  end
end