Class: Stupidedi::Either::Failure
- Inherits:
-
Stupidedi::Either
- Object
- Stupidedi::Either
- Stupidedi::Either::Failure
- Defined in:
- lib/stupidedi/either.rb
Direct Known Subclasses
Instance Attribute Summary (collapse)
-
- reason
readonly
Returns the value of attribute reason.
Filtering the Value (collapse)
Transforming the Value (collapse)
- - (Failure) explain {|reason| ... }
- - (Failure) flatmap
- - (Failure) map
- - (Either) or {|reason| ... }
Instance Method Summary (collapse)
- - (Boolean) ==(other)
- - (Failure) copy(changes = {})
-
- (Boolean) defined?
False.
- - fetch(default)
-
- (Failure) initialize(reason)
constructor
A new instance of Failure.
- - (String) inspect
- - pretty_print(q)
- - tap
Methods inherited from Stupidedi::Either
Constructor Details
- (Failure) initialize(reason)
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
- (Boolean) ==(other)
238 239 240 |
# File 'lib/stupidedi/either.rb', line 238 def ==(other) other.is_a?(self.class) and other.reason == @reason end |
- (Failure) copy(changes = {})
167 168 169 170 |
# File 'lib/stupidedi/either.rb', line 167 def copy(changes = {}) Failure.new \ changes.fetch(:reason, @reason) end |
- (Boolean) defined?
False
173 174 175 |
# File 'lib/stupidedi/either.rb', line 173 def defined? false end |
- (Failure) explain {|reason| ... }
226 227 228 |
# File 'lib/stupidedi/either.rb', line 226 def explain(&block) copy(:reason => deconstruct(block)) end |
- fetch(default)
177 178 179 |
# File 'lib/stupidedi/either.rb', line 177 def fetch(default) default end |
- (String) inspect
252 253 254 |
# File 'lib/stupidedi/either.rb', line 252 def inspect "Either.failure(#{@reason.inspect})" end |
- (Either) or {|reason| ... }
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 |
- (Failure) reject(reason = nil)
190 191 192 |
# File 'lib/stupidedi/either.rb', line 190 def reject(reason = nil) self end |
- (Failure) select(reason = nil)
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 |