X-Git-Url: https://git.adam-barratt.org.uk/?p=mirror%2Fdsa-puppet.git;a=blobdiff_plain;f=3rdparty%2Fmodules%2Fstdlib%2Flib%2Fpuppet%2Fparser%2Ffunctions%2Fconvert_base.rb;h=3e4c89fa8bff4650312d097e60e0a1bfc8799722;hp=da5ff2690afa6559b4715706b7b6069dcb2a73b9;hb=30caaa85aed7015ca0d77216bff175eebd917eb7;hpb=6f656bd4265e3dab13b9af2bf96e9044322e9d8f diff --git a/3rdparty/modules/stdlib/lib/puppet/parser/functions/convert_base.rb b/3rdparty/modules/stdlib/lib/puppet/parser/functions/convert_base.rb index da5ff2690..3e4c89fa8 100644 --- a/3rdparty/modules/stdlib/lib/puppet/parser/functions/convert_base.rb +++ b/3rdparty/modules/stdlib/lib/puppet/parser/functions/convert_base.rb @@ -3,18 +3,28 @@ # module Puppet::Parser::Functions newfunction(:convert_base, :type => :rvalue, :arity => 2, :doc => <<-'DOC') do |args| - Converts a given integer or base 10 string representing an integer to a specified base, as a string. + @summary + Converts a given integer or base 10 string representing an integer to a + specified base, as a string. - Usage: + @return + converted value as a string - $binary_repr = convert_base(5, 2) # $binary_repr is now set to "101" - $hex_repr = convert_base("254", "16") # $hex_repr is now set to "fe" + @example Example usage - Note: Since Puppet 4.5.0 this can be done with String.new() and its many formatting options: + convert_base(5, 2)` results in: `'101'` + convert_base('254', '16')` results in: `'fe'` - $binary_repr = String(5, '%b') # results in "101" - $hex_repr = String(254, "%x") # results in "fe" - $hex_repr = String(254, "%#x") # results in "0xfe" + > *Note:* + Since Puppet 4.5.0 this can be done with the built-in + [`String.new`](https://puppet.com/docs/puppet/latest/function.html#integer-to-string) + function and its many formatting options: + + `$binary_repr = String(5, '%b')` return `"101"` + `$hex_repr = String(254, "%x")` return `"fe"` + `$hex_repr = String(254, "%#x")` return `"0xfe"` + + @return [String] The converted value as a String DOC raise Puppet::ParseError, 'convert_base(): First argument must be either a string or an integer' unless args[0].is_a?(Integer) || args[0].is_a?(String)