Class: Monadic::Nothing

Inherits:
Maybe show all
Defined in:
lib/monadic/maybe.rb

Overview

Represents a NullObject

Class Method Summary collapse

Methods inherited from Maybe

#empty?, #select, #truly?, unit

Methods included from Monad

#==, #bind, #fetch, #flat_map, #initialize, #join, #map, #to_ary, #to_s

Class Method Details

.===(other) ⇒ Object



116
117
118
# File 'lib/monadic/maybe.rb', line 116

def ===(other)
  other == Nothing
end

.empty?Boolean

Returns:

  • (Boolean)


112
113
114
# File 'lib/monadic/maybe.rb', line 112

def empty?
  true
end

.fetch(default = nil) ⇒ Object Also known as: _

Returns the default value passed.

Returns:

  • the default value passed



77
78
79
80
# File 'lib/monadic/maybe.rb', line 77

def fetch(default=nil)
  return self if default.nil?
  return default
end

.method_missing(m, *args) ⇒ Object



83
84
85
# File 'lib/monadic/maybe.rb', line 83

def method_missing(m, *args)
  self
end

.or(other) ⇒ Object

Returns an alternative value, the passed value is coerced into Maybe, thus Nothing.or(1) will be Just(1).

Returns:

  • an alternative value, the passed value is coerced into Maybe, thus Nothing.or(1) will be Just(1)



88
89
90
# File 'lib/monadic/maybe.rb', line 88

def or(other)
  Maybe.unit(other)
end

.to_aryObject Also known as: to_a

def respond_to? end



95
96
97
# File 'lib/monadic/maybe.rb', line 95

def to_ary
  []
end

.to_json(*args) ⇒ Object



104
105
106
# File 'lib/monadic/maybe.rb', line 104

def to_json(*args)
  'null'
end

.to_s(*args) ⇒ Object



100
101
102
# File 'lib/monadic/maybe.rb', line 100

def to_s(*args)
  'Nothing'
end

.truly?Boolean

Returns:

  • (Boolean)


108
109
110
# File 'lib/monadic/maybe.rb', line 108

def truly?
  false
end