Sha256: 9de26cddf75f66e63b49e8335ca7b5ba92c023f098baf87318351221bc580d84

Contents?: true

Size: 574 Bytes

Versions: 13

Compression:

Stored size: 574 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_f
      0.0
    end

    def to_i
      0
    end

    def to_a
      []
    end

    def inspect
      'NULL'
    end

    def nil?
      true
    end

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

  NULL = Class.new(Module) do
    include Tins::Null
  end.new.freeze
end

require 'tins/alias'

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
tins-0.5.0 lib/tins/null.rb
tins-0.4.3 lib/tins/null.rb
tins-0.4.2 lib/tins/null.rb
tins-0.4.1 lib/tins/null.rb
tins-0.4.0 lib/tins/null.rb
tins-0.3.14 lib/tins/null.rb
tins-0.3.13 lib/tins/null.rb
tins-0.3.12 lib/tins/null.rb
tins-0.3.11 lib/tins/null.rb
tins-0.3.10 lib/tins/null.rb
tins-0.3.9 lib/tins/null.rb
tins-0.3.8 lib/tins/null.rb
tins-0.3.7 lib/tins/null.rb