Class: NullClass

Inherits:
Object show all
Defined in:
lib/standard/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.

TODO: Perhaps NullClass should be called NackClass?

Class Method Summary (collapse)

Instance Method Summary (collapse)

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

- (Object) method_missing(sym, *args)



20
21
22
23
# File 'lib/standard/facets/nullclass.rb', line 20

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

Class Method Details

+ (Object) new



12
13
14
# File 'lib/standard/facets/nullclass.rb', line 12

def new
  @null ||= NullClass.allocate
end

Instance Method Details

- (Object) [](key)



19
# File 'lib/standard/facets/nullclass.rb', line 19

def [](key); nil; end

- (Object) inspect



16
# File 'lib/standard/facets/nullclass.rb', line 16

def inspect ; 'null' ; end

- (Boolean) nil?

Returns:

  • (Boolean)


17
# File 'lib/standard/facets/nullclass.rb', line 17

def nil?  ; true ; end

- (Boolean) null?

Returns:

  • (Boolean)


18
# File 'lib/standard/facets/nullclass.rb', line 18

def null? ; true ; end