Sha256: 4bf6cadcebfdcbf864b705d5b6547f0f592964c8994b4f65b148ad3a2132dec5

Contents?: true

Size: 707 Bytes

Versions: 10

Compression:

Stored size: 707 Bytes

Contents

# = 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.
#
# TODO: Perhaps NullClass should be called NackClass?

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

# Copyright (c) 2005 Thomas Sawyer

Version data entries

10 entries across 9 versions & 2 rubygems

Version Path
facets-glimmer-3.2.0 lib/standard/facets/nullclass.rb
facets-3.1.0 lib/standard/facets/nullclass.rb
facets-3.0.0 lib/standard/facets/nullclass.rb
facets-2.9.3 lib/standard/facets/nullclass.rb
facets-2.9.2 src/supplemental/facets/nullclass.rb
facets-2.9.2 lib/supplemental/facets/nullclass.rb
facets-2.9.1 lib/supplemental/facets/nullclass.rb
facets-2.9.0 lib/more/facets/nullclass.rb
facets-2.9.0.pre.2 lib/more/facets/nullclass.rb
facets-2.9.0.pre.1 lib/more/facets/nullclass.rb