Sha256: 76f2c1f9d72212a30a35b19a0a20f52bafba272d87f960ecc5d02a9f15383910

Contents?: true

Size: 648 Bytes

Versions: 2

Compression:

Stored size: 648 Bytes

Contents

# encoding: utf-8
# frozen_string_literal: true

module Mixture
  module Types
    # The boolean type.  Unfortunately, ruby doesn't have a clear cut
    # boolean primitive (it has `TrueClass` and `FalseClass`, but no
    # `Boolean` class), so we set the primitive to nil to prevent
    # odd stuff from happening.  It can still be matched by other
    # values.
    class Boolean < Object
      register
      options[:primitive] = nil
      options[:method] = :to_boolean
      as :bool, :boolean, true, false

      constraints.clear
      constraint do |value|
        [TrueClass, FalseClass].include?(value.class)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mixture-0.7.1 lib/mixture/types/boolean.rb
mixture-0.7.0 lib/mixture/types/boolean.rb