Class: NullClass

Inherits:
Object show all
Defined in:
lib/more/facets/nullclass.rb

Overview

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 Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args) ⇒ Object



49
50
51
52
# File 'lib/more/facets/nullclass.rb', line 49

def method_missing(sym, *args)
  return nil if sym.to_s[-1,1] == '?'
  self
end

Class Method Details

.newObject



41
42
43
# File 'lib/more/facets/nullclass.rb', line 41

def new
  @null ||= NullClass.allocate
end

Instance Method Details

#[](key) ⇒ Object



48
# File 'lib/more/facets/nullclass.rb', line 48

def [](key); nil; end

#inspectObject



45
# File 'lib/more/facets/nullclass.rb', line 45

def inspect ; 'null' ; end

#nil?Boolean

Returns:

  • (Boolean)


46
# File 'lib/more/facets/nullclass.rb', line 46

def nil?  ; true ; end

#null?Boolean

Returns:

  • (Boolean)


47
# File 'lib/more/facets/nullclass.rb', line 47

def null? ; true ; end