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
Instance Method Summary collapse
- #==(other) ⇒ Boolean
- #copy(changes = {}) ⇒ Failure
-
#defined? ⇒ Boolean
False.
- #fetch(default = nil)
-
#initialize(reason) ⇒ Failure
constructor
A new instance of Failure.
- #inspect ⇒ String
- #pretty_print(q)
- #tap
Methods inherited from Stupidedi::Either
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
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
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.
173 174 175 |
# File 'lib/stupidedi/either.rb', line 173 def defined? false end |
#explain {|reason| ... } ⇒ Failure
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 |
#inspect ⇒ String
252 253 254 |
# File 'lib/stupidedi/either.rb', line 252 def inspect "Either.failure(#{@reason.inspect})" end |
#or {|reason| ... } ⇒ Either
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
190 191 192 |
# File 'lib/stupidedi/either.rb', line 190 def reject(reason = nil) self end |
#select(reason = nil) ⇒ Failure
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 |