Sha256: 57b74b2f51ed62c6318512f6040a758afcc9388791d5b495e9090134d5f0ef3f

Contents?: true

Size: 641 Bytes

Versions: 10

Compression:

Stored size: 641 Bytes

Contents

# frozen_string_literal: true

require 'delegate'

module MediaTypes
  class Scheme
    class CaseEqualityWithNil < SimpleDelegator

      # Same as the wrapped {Object#===}, but also allows for NilCLass
      def ===(other)
        other.nil? || super
      end
    end

    # noinspection RubyInstanceMethodNamingConvention
    ##
    # Allows the wrapped +klazz+ to be nil
    #
    # @param [Class] klazz the class that +it+ must be the if +it+ is not NilClass
    # @return [CaseEqualityWithNil]
    def AllowNil(klazz) # rubocop:disable Naming/MethodName
      CaseEqualityWithNil.new(klazz)
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
media_types-0.4.1 lib/media_types/scheme/allow_nil.rb
media_types-0.4.0 lib/media_types/scheme/allow_nil.rb
media_types-0.3.0 lib/media_types/scheme/allow_nil.rb
media_types-0.2.6 lib/media_types/scheme/allow_nil.rb
media_types-0.2.5 lib/media_types/scheme/allow_nil.rb
media_types-0.2.4 lib/media_types/scheme/allow_nil.rb
media_types-0.2.3 lib/media_types/scheme/allow_nil.rb
media_types-0.2.2 lib/media_types/scheme/allow_nil.rb
media_types-0.2.1 lib/media_types/scheme/allow_nil.rb
media_types-0.2.0 lib/media_types/scheme/allow_nil.rb