class Gorillib::Factory::FloatFactory
Returns arg converted to a float.
-
Numeric types are converted directly
-
Strings strictly conform to numeric representation or an error is raised (which differs from the behavior of String#to_f)
-
Strings in radix format (an exact hexadecimal encoding of a number) are properly interpreted.
-
Octal is not interpreted! This means an
IntegerFactory
receiving ‘011’ will get 9, aFloatFactory
11.0 -
Other types are converted using obj.to_f.
@example
FloatFactory.receive(1) #=> 1.0 FloatFactory.receive("123.456") #=> 123.456 FloatFactory.receive("0x1.999999999999ap-4" #=> 0.1
@example FloatFactory
is strict in some cases where GraciousFloatFactory
is not
FloatFactory.receive("1_23e9f") #=> (error)
@example FloatFactory() is not as gullible as GraciousFloatFactory
FloatFactory.receive("7eleven") #=> (error) FloatFactory.receive("nonzero") #=> (error)
Public Instance Methods
convert(obj)
click to toggle source
# File lib/gorillib/model/factories.rb, line 361 def convert(obj) Float(obj) ; end