Puppet Function: to_integer
- Defined in:
- lib/puppet/parser/functions/to_integer.rb
- Function type:
- Ruby 3.x API
Overview
Converts the argument into an Integer
.
Only works if the passed argument responds to the to_i()
Ruby
method.
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/puppet/parser/functions/to_integer.rb', line 2 newfunction(:to_integer, :type => :rvalue, :arity => 1, :doc => <<-EOS) do |arguments| arg = arguments[0] Converts the argument into an `Integer`. Only works if the passed argument responds to the `to_i()` Ruby method. @param input [Any] The argument to convert into an `Integer` @return [Integer] EOS return arg if arg.is_a?(Integer) if arg.respond_to?(:to_i) return arg.to_i else raise(Puppet::ParseError, "to_integer(): Object type '#{arg.class}' cannot be converted to an Integer") end end |