class Gorillib::Factory::IntegerFactory

Converts arg to a Fixnum or Bignum.

@example

IntegerFactory.receive(123.999)    #=> 123
IntegerFactory.receive(Time.new)   #=> 1204973019

@example IntegerFactory() handles floating-point numbers correctly (as opposed to ‘Integer()` and GraciousIntegerFactory)

IntegerFactory.receive("98.6")     #=> 98
IntegerFactory.receive("1234.5e3") #=> 1_234_500

@example IntegerFactory has love for your hexadecimal, and disturbingly considers 0-prefixed numbers to be octal.

IntegerFactory.receive("0x1a")     #=> 26
IntegerFactory.receive("011")      #=> 9

@example IntegerFactory() is not as gullible, or generous as GraciousIntegerFactory

IntegerFactory.receive("7eleven")  #=> (error)
IntegerFactory.receive("nonzero")  #=> (error)
IntegerFactory.receive("123_456L") #=> (error)

@note returns Bignum or Fixnum (instances of either are ‘is_a?(Integer)`)

Public Instance Methods

convert(obj) click to toggle source
# File lib/gorillib/factories.rb, line 294
def convert(obj)
  Integer(obj)
end