Sha256: cfeaf4905710d003e4821a8bea92af6f32f8b8cfb27bb1a06fba6997ad790ebb

Contents?: true

Size: 927 Bytes

Versions: 2

Compression:

Stored size: 927 Bytes

Contents

# frozen_string_literal: true

require "much-not-given/version"
require "much-mixin"

module MuchNotGiven
  include MuchMixin

  mixin_class_methods do
    def not_given
      @not_given ||=
        begin
          Class.new{
            def initialize(receiver_name)
              @receiver_name = receiver_name
            end

            def blank?
              true
            end

            def present?
              false
            end

            def to_s
              "#{@receiver_name}.not_given"
            end

            def inspect
              to_s
            end

            def ==(other)
              if other.is_a?(self.class)
                true
              else
                super
              end
            end
          }.new(inspect)
        end
    end

    def not_given?(value)
      value == not_given
    end

    def given?(value)
      value != not_given
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
much-not-given-0.1.3 lib/much-not-given.rb
much-not-given-0.1.2 lib/much-not-given.rb