Class: Gorillib::Factory::GraciousIntegerFactory
- Inherits:
-
IntegerFactory
- Object
- BaseFactory
- ConvertingFactory
- IntegerFactory
- Gorillib::Factory::GraciousIntegerFactory
- Defined in:
- lib/gorillib/factories.rb
Overview
Note:
returns Bignum or Fixnum (instances of either are is_a?(Integer)
)
Converts arg to a Fixnum or Bignum.
- Numeric types are converted directly, with floating point numbers being truncated
- Strings are interpreted using
#to_i
, so: ** radix indicators (0, 0b, and 0x) are IGNORED -- '011' means 11, not 9; '0x22' means 0, not 34 ** Strings will be very generously interpreted - Non-string values will be converted using to_i
Instance Method Summary collapse
-
#convert(obj) ⇒ Object
See examples/benchmark before 'improving' this method.
Methods inherited from ConvertingFactory
Methods inherited from BaseFactory
#blankish?, blankish?, #initialize, #native?, native?, #receive, typename, #typename
Constructor Details
This class inherits a constructor from Gorillib::Factory::BaseFactory
Instance Method Details
#convert(obj) ⇒ Object
See examples/benchmark before 'improving' this method.
329 330 331 332 333 334 335 |
# File 'lib/gorillib/factories.rb', line 329 def convert(obj) if ::String === obj then obj = obj.to_s.tr(::Gorillib::Factory::FLT_CRUFT_CHARS, '') ; obj = ::Kernel::Float(obj) if ::Gorillib::Factory::FLT_NOT_INT_RE === obj ; end ::Kernel::Integer(obj) end |