Sha256: 06e915f2a0989748849727d6887d4dbafa92b27b59df2950132beb115bfb7667

Contents?: true

Size: 823 Bytes

Versions: 1

Compression:

Stored size: 823 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
      #
      # @return [Float]
      #
      # @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.5 lib/virtus/attribute/float.rb