Sha256: 0e16eebcf9c5dee6281bbcd18c851b8de72adcea171f05b38bd21d8d97e7bf5a

Contents?: true

Size: 766 Bytes

Versions: 2

Compression:

Stored size: 766 Bytes

Contents

# encoding: utf-8

module Mixture
  module Types
    # An object.  This adds the basic constraints all types (that
    # inherit from Object) have; i.e., it must be an object, and
    # it must be the type's primitive.
    class Object < Type
      options[:primitive] = ::Object
      options[:method] = :to_object
      as :object

      constraint do |value|
        # This may seem a bit odd, but this returns false for
        # BasicObject; and since this is meant to represent Objects,
        # we want to make sure that the value isn't a BasicObject.
        # rubocop:disable Style/CaseEquality
        ::Object === value
        # rubocop:enable Style/CaseEquality
      end
      constraint { |value| value.is_a?(options[:primitive]) }
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mixture-0.3.1 lib/mixture/types/object.rb
mixture-0.3.0 lib/mixture/types/object.rb