Class: ActiveModel::Type::Float

Inherits:
Value
  • Object
show all
Includes:
Helpers::Numeric
Defined in:
lib/active_model/type/float.rb

Overview

:nodoc:

Instance Attribute Summary

Attributes inherited from Value

#limit, #precision, #scale

Instance Method Summary collapse

Methods included from Helpers::Numeric

#cast, #changed?, #serialize

Methods inherited from Value

#==, #assert_valid_value, #binary?, #cast, #changed?, #changed_in_place?, #deserialize, #force_equality?, #hash, #initialize, #map, #serializable?, #serialize, #value_constructed_by_mass_assignment?

Constructor Details

This class inherits a constructor from ActiveModel::Type::Value

Instance Method Details

#typeObject



10
11
12
# File 'lib/active_model/type/float.rb', line 10

def type
  :float
end

#type_cast_for_schema(value) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/active_model/type/float.rb', line 14

def type_cast_for_schema(value)
  return "::Float::NAN" if value.try(:nan?)
  case value
  when ::Float::INFINITY then "::Float::INFINITY"
  when -::Float::INFINITY then "-::Float::INFINITY"
  else super
  end
end