Class: NullClass

Inherits:
Object show all
Includes:
Falsiness, RecursiveMethodMissing, TruthyBooleanOperators
Defined in:
lib/null.rb

Overview

We implement the Null Object Pattern, i.e. most methods called on us will return self. Also, boolean logical operators for true, false, and nil have been redefined so that they depend on the falsy?

Direct Known Subclasses

VoidClass

Instance Method Summary collapse

Methods included from RecursiveMethodMissing

#method_missing

Methods included from TruthyBooleanOperators

#&, #^, #|

Methods included from Falsiness

#!, #falsy?, #truthy?

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class RecursiveMethodMissing

Instance Method Details

#coerce(x) ⇒ Object

Make Numeric operations involving null return null.



148
149
150
# File 'lib/null.rb', line 148

def coerce(x)
	[null, null]
end

#empty?Boolean

:nodoc:

Returns:

  • (Boolean)


136
# File 'lib/null.rb', line 136

def   empty?()   true end

#inspectObject

“null”



138
# File 'lib/null.rb', line 138

def  inspect() 'null' end

#nil?Boolean

:nodoc:

Returns:

  • (Boolean)


134
# File 'lib/null.rb', line 134

def     nil?()   true end

#null?Boolean

:nodoc:

Returns:

  • (Boolean)


135
# File 'lib/null.rb', line 135

def    null?()   true end

#present?Boolean

:nodoc:

Returns:

  • (Boolean)


139
# File 'lib/null.rb', line 139

def present?()  false end

#tap?Boolean

Require a block, but don’t use it; then return self.

Returns:

  • (Boolean)

Raises:

  • (LocalJumpError)


142
143
144
145
# File 'lib/null.rb', line 142

def tap? # :nodoc:
	raise(LocalJumpError, 'no block given') unless block_given?
	self
end

#to_nil?Boolean

:nodoc:

Returns:

  • (Boolean)


137
# File 'lib/null.rb', line 137

def  to_nil?()    nil end

#to_sObject

“”



133
# File 'lib/null.rb', line 133

def     to_s()    nil end