Sha256: 8b9b2a95e7861a26a4ad19db0e132156901a76dd6527496135e157747a221be7

Contents?: true

Size: 560 Bytes

Versions: 9

Compression:

Stored size: 560 Bytes

Contents

# encoding: utf-8

module Mixture
  module Coerce
    # Handles coercion of the Rational class.
    class Rational < Base
      type Types::Rational

      coerce_to(Types::Object, Itself)
      coerce_to(Types::Rational, Itself)
      coerce_to(Types::Time) { |value| ::Time.at(value) }
      coerce_to(Types::Date) { |value| ::Time.at(value).to_date }
      coerce_to(Types::DateTime) { |value| ::Time.at(value).to_datetime }
      coerce_to(Types::Float, :to_f)
      coerce_to(Types::Integer, :to_i)
      coerce_to(Types::String, :to_s)
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
mixture-0.5.1 lib/mixture/coerce/rational.rb
mixture-0.5.0 lib/mixture/coerce/rational.rb
mixture-0.4.0 lib/mixture/coerce/rational.rb
mixture-0.3.6 lib/mixture/coerce/rational.rb
mixture-0.3.5 lib/mixture/coerce/rational.rb
mixture-0.3.4 lib/mixture/coerce/rational.rb
mixture-0.3.2 lib/mixture/coerce/rational.rb
mixture-0.3.1 lib/mixture/coerce/rational.rb
mixture-0.3.0 lib/mixture/coerce/rational.rb