Puppet Function: simplib::to_integer
- Defined in:
- lib/puppet/functions/simplib/to_integer.rb
- Function type:
- Ruby 4.x API
Overview
Converts the argument into an ‘Integer`.
Terminates catalog compilation if the argument’s class does not respond to the ‘to_i()` Ruby method.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/puppet/functions/simplib/to_integer.rb', line 6 Puppet::Functions.create_function(:'simplib::to_integer') do # @param input The argument to convert into an `Integer` # @return [Integer] Converted input # @raise [RuntimeError] if ``input`` does not implement a ``to_i()`` # method dispatch :to_integer do required_param 'Any', :input end def to_integer(input) return input if input.is_a?(Integer) if input.respond_to?(:to_i) return input.to_i else fail("simplib::to_integer(): Object type '#{input.class}' cannot be converted to an Integer") end end end |