class Coercible::Coercer::Numeric
Base class for all numeric Coercion classes
Public Instance Methods
to_decimal(value)
click to toggle source
Coerce a BigDecimal instance from a numeric object
@example
coercer[Numeric].to_decimal(Rational(2, 2)) # => BigDecimal('1.0')
@param [Numeric] value
@return [BigDecimal]
@api public
# File lib/coercible/coercer/numeric.rb, line 60 def to_decimal(value) to_string(value).to_d end
to_float(value)
click to toggle source
Creates a Float instance from a numeric object
@example
coercer[Numeric].to_float(Rational(2, 2)) # => 1.0
@param [Numeric] value
@return [Float]
@api public
# File lib/coercible/coercer/numeric.rb, line 46 def to_float(value) value.to_f end
to_integer(value)
click to toggle source
Creates an Integer instance from a numeric object
@example
coercer[Numeric].to_integer(Rational(2, 2)) # => 1
@param [Numeric] value
@return [Integer]
@api public
# File lib/coercible/coercer/numeric.rb, line 32 def to_integer(value) value.to_i end
to_string(value)
click to toggle source
Coerce given value to String
@example
coercer[Numeric].to_string(Rational(2, 2)) # => "1.0"
@param [Numeric] value
@return [String]
@api public
# File lib/coercible/coercer/numeric.rb, line 18 def to_string(value) value.to_s end