Sha256: 19fc44cb024e680833d4904018257d6112b0e4750fce0c1d315418e8b7618169

Contents?: true

Size: 1.4 KB

Versions: 7

Compression:

Stored size: 1.4 KB

Contents

#--
# NullClass
#
# Copyright (c) 2005 Thomas Sawyer
#
# Ruby License
#
# This module is free software. You may use, modify, and/or redistribute this
# software under the same terms as Ruby.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.
#
# ==========================================================================
# Revision History ::
# --------------------------------------------------------------------------
#  2005.10.28  trans     * Created.
# ==========================================================================

# :title: NullClass
#
# NullClass is essentially NilClass but it differs in one
# important way. When a method is called against it that it
# deoesn't have, it will simply return null value rather then
# raise an error.

class NullClass #< NilClass
  class << self
    def new
      @null ||= NullClass.allocate
    end
  end
  def inspect ; 'null' ; end
  def nil?  ; true ; end
  def null? ; true ; end
  def [](key); nil; end
  def method_missing(sym, *args)
    return nil if sym.to_s[-1,1] == '?'
    self
  end
end

module Kernel
  def null
    NullClass.new
  end
end

class Object
  def null?
    false
  end
end



#  _____         _
# |_   _|__  ___| |_
#   | |/ _ \/ __| __|
#   | |  __/\__ \ |_
#   |_|\___||___/\__|
#

# TODO

=begin #testing
=end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
facets-1.0.3 packages/more/lib/facet/nullclass.rb
facets-1.2.0 lib/facets/more/nullclass.rb
facets-1.2.1 lib/facets/more/nullclass.rb
facets-1.3.0 lib/facets/more/nullclass.rb
facets-1.3.1 lib/facets/more/nullclass.rb
facets-1.3.2 lib/facets/more/nullclass.rb
facets-1.3.3 lib/facets/more/nullclass.rb