Sha256: b12812371c54366291d95058bc3ff4815e3265b89e00084b5591ea66734777e4

Contents?: true

Size: 791 Bytes

Versions: 1

Compression:

Stored size: 791 Bytes

Contents

module Virtus
  class Attribute

    # Example usage:
    #
    #   class ExchangeRate
    #     include Virtus
    #
    #     attribute :dollar, Float
    #   end
    #
    #   ExchangeRate.new(:dollar => 2.69)
    #
    #   # typecasting from a string
    #   ExchangeRate.new(:dollar => '2.69')
    #
    #   # typecasting from an integer
    #   ExchangeRate.new(:dollar => 2)
    #
    #   # typecasting from an object which implements #to_f
    #   ExchangeRate.new(:dollar => BigDecimal.new('2.69')
    #
    class Float < Numeric
      primitive ::Float

      # @see Virtus::Typecast::Numeric.to_f
      #
      # @api private
      def typecast_to_primitive(value)
        Typecast::Numeric.to_f(value)
      end

    end # class Float
  end # class Attribute
end # module Virtus

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
virtus-0.0.4 lib/virtus/attribute/float.rb