module Origin::Extensions::Numeric::ClassMethods

Public Instance Methods

__numeric__(object) click to toggle source

Get the object as a numeric.

@api private

@example Get the object as numeric.

Object.__numeric__("1.442")

@param [ Object ] object The object to convert.

@return [ Object ] The converted number.

@since 1.0.0

# File lib/origin/extensions/numeric.rb, line 57
def __numeric__(object)
  object.to_s =~ /(^[-+]?[0-9]+$)|(\.0+$)|(\.$)/ ? object.to_i : Float(object)
end
evolve(object) click to toggle source

Evolve the object to an integer.

@example Evolve to integers.

Integer.evolve("1")

@param [ Object ] object The object to evolve.

@return [ Integer ] The evolved object.

@since 1.0.0

# File lib/origin/extensions/numeric.rb, line 71
def evolve(object)
  __evolve__(object) do |obj|
    __numeric__(obj) rescue obj
  end
end