Class: NullClass
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
41
42
43
|
# File 'lib/more/facets/nullclass.rb', line 41
def new
@null ||= NullClass.allocate
end
|
Instance Method Details
48
|
# File 'lib/more/facets/nullclass.rb', line 48
def [](key); nil; end
|
45
|
# File 'lib/more/facets/nullclass.rb', line 45
def inspect ; 'null' ; end
|
#nil? ⇒ Boolean
46
|
# File 'lib/more/facets/nullclass.rb', line 46
def nil? ; true ; end
|
#null? ⇒ Boolean
47
|
# File 'lib/more/facets/nullclass.rb', line 47
def null? ; true ; end
|