Sha256: 01b71e438749e92d474dcfc940e791b5d79cede31fd97f2f5fad510c5d0b8b3b

Contents?: true

Size: 728 Bytes

Versions: 17

Compression:

Stored size: 728 Bytes

Contents

module Tins
  # Implementation of the null object pattern in Ruby.
  module Null
    def method_missing(*)
      self
    end

    def const_missing(*)
      self
    end

    def to_s
      ''
    end

    def to_str
      nil
    end

    def to_f
      0.0
    end

    def to_i
      0
    end

    def to_int
      nil
    end

    def to_a
      []
    end

    def to_ary
      nil
    end

    def inspect
      'NULL'
    end

    def nil?
      true
    end

    def blank?
      true
    end

    module Kernel
      def Null(value = nil)
        value.nil? ? Tins::NULL : value
      end
    end
  end

  class NullClass < Module
    include Tins::Null
  end

  NULL = NullClass.new.freeze
end

require 'tins/alias'

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
tins-0.10.0 lib/tins/null.rb
tins-0.9.0 lib/tins/null.rb
tins-0.8.4 lib/tins/null.rb
tins-0.8.3 lib/tins/null.rb
tins-0.8.2 lib/tins/null.rb
tins-0.8.0 lib/tins/null.rb
tins-0.7.4 lib/tins/null.rb
tins-0.7.3 lib/tins/null.rb
tins-0.7.2 lib/tins/null.rb
tins-0.7.1 lib/tins/null.rb
tins-0.7.0 lib/tins/null.rb
tins-0.6.0 lib/tins/null.rb
tins-0.5.6 lib/tins/null.rb
tins-0.5.5 lib/tins/null.rb
tins-0.5.4 lib/tins/null.rb
tins-0.5.3 lib/tins/null.rb
tins-0.5.2 lib/tins/null.rb