Class: Stupidedi::Either::Failure

Inherits:
Stupidedi::Either show all
Defined in:
lib/stupidedi/either.rb

Direct Known Subclasses

Reader::Failure

Instance Attribute Summary collapse

Filtering the Value collapse

Transforming the Value collapse

Instance Method Summary collapse

Methods inherited from Stupidedi::Either

failure, success

Constructor Details

#initialize(reason) ⇒ Failure

Returns a new instance of Failure.



162
163
164
# File 'lib/stupidedi/either.rb', line 162

def initialize(reason)
  @reason = reason
end

Instance Attribute Details

#reason (readonly)

Returns the value of attribute reason.



160
161
162
# File 'lib/stupidedi/either.rb', line 160

def reason
  @reason
end

Instance Method Details

#==(other) ⇒ Boolean

Returns:

  • (Boolean)


238
239
240
# File 'lib/stupidedi/either.rb', line 238

def ==(other)
  other.is_a?(self.class) and other.reason == @reason
end

#copy(changes = {}) ⇒ Failure

Returns:



167
168
169
170
# File 'lib/stupidedi/either.rb', line 167

def copy(changes = {})
  Failure.new \
    changes.fetch(:reason, @reason)
end

#defined?Boolean

Returns false.

Returns:

  • (Boolean)

    false



173
174
175
# File 'lib/stupidedi/either.rb', line 173

def defined?
  false
end

#explain {|reason| ... } ⇒ Failure

Yield Parameters:

  • reason

Yield Returns:

  • reason

Returns:



226
227
228
# File 'lib/stupidedi/either.rb', line 226

def explain(&block)
  copy(:reason => deconstruct(block))
end

#fetch(default = nil)



177
178
179
# File 'lib/stupidedi/either.rb', line 177

def fetch(default = nil)
  default
end

#flatmapFailure

Returns:



206
207
208
# File 'lib/stupidedi/either.rb', line 206

def flatmap
  self
end

#inspectString

Returns:

  • (String)


252
253
254
# File 'lib/stupidedi/either.rb', line 252

def inspect
  "Either.failure(#{@reason.inspect})"
end

#mapFailure

Returns:



201
202
203
# File 'lib/stupidedi/either.rb', line 201

def map
  self
end

#or {|reason| ... } ⇒ Either

Yield Parameters:

  • reason

Yield Returns:

Returns:



213
214
215
216
217
218
219
220
221
# File 'lib/stupidedi/either.rb', line 213

def or(&block)
  result = deconstruct(block)

  if result.is_a?(Either)
    result
  else
    raise TypeError, "block did not return an instance of Either"
  end
end

#pretty_print(q)

This method returns an undefined value.



243
244
245
246
247
248
249
# File 'lib/stupidedi/either.rb', line 243

def pretty_print(q)
  q.text("Either.failure")
  q.group(2, "(", ")") do
    q.breakable ""
    q.pp @reason
  end
end

#reject(reason = nil) ⇒ Failure

Returns:



190
191
192
# File 'lib/stupidedi/either.rb', line 190

def reject(reason = nil)
  self
end

#select(reason = nil) ⇒ Failure

Returns:



185
186
187
# File 'lib/stupidedi/either.rb', line 185

def select(reason = nil)
  self
end

#tap



233
234
235
# File 'lib/stupidedi/either.rb', line 233

def tap
  self
end