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.



158
159
160
# File 'lib/null.rb', line 158

def coerce(x)
  [null, null]
end

#empty?Boolean

:nodoc:

Returns:

  • (Boolean)


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

def   empty?()   true end

#inspectObject

“null”



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

def  inspect() 'null' end

#nil?Boolean

:nodoc:

Returns:

  • (Boolean)


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

def     nil?()   true end

#null?Boolean

:nodoc:

Returns:

  • (Boolean)


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

def    null?()   true end

#present?Boolean

:nodoc:

Returns:

  • (Boolean)


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

def present?()  false end

#tap?Boolean

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

Returns:

  • (Boolean)

Raises:

  • (LocalJumpError)


152
153
154
155
# File 'lib/null.rb', line 152

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

#to_nil?Boolean

:nodoc:

Returns:

  • (Boolean)


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

def  to_nil?()    nil end

#to_null?Boolean

:nodoc:

Returns:

  • (Boolean)


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

def to_null?()   null end

#to_sObject

“”



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

def     to_s()    nil end