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 ⇒ Object
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) ⇒ Object
-
#initialize(reason) ⇒ Failure
constructor
A new instance of Failure.
- #inspect ⇒ String
- #pretty_print(q) ⇒ void
- #tap ⇒ Object
Methods inherited from Stupidedi::Either
Constructor Details
#initialize(reason) ⇒ Failure
Returns a new instance of Failure.
166 167 168 |
# File 'lib/stupidedi/either.rb', line 166 def initialize(reason) @reason = reason end |
Instance Attribute Details
#reason ⇒ Object (readonly)
Returns the value of attribute reason.
164 165 166 |
# File 'lib/stupidedi/either.rb', line 164 def reason @reason end |
Instance Method Details
#==(other) ⇒ Boolean
242 243 244 |
# File 'lib/stupidedi/either.rb', line 242 def ==(other) other.is_a?(self.class) and other.reason == @reason end |
#copy(changes = {}) ⇒ Failure
171 172 173 174 |
# File 'lib/stupidedi/either.rb', line 171 def copy(changes = {}) Failure.new \ changes.fetch(:reason, @reason) end |
#defined? ⇒ Boolean
Returns false.
177 178 179 |
# File 'lib/stupidedi/either.rb', line 177 def defined? false end |
#explain {|reason| ... } ⇒ Failure
230 231 232 |
# File 'lib/stupidedi/either.rb', line 230 def explain(&block) copy(:reason => deconstruct(block)) end |
#fetch(default = nil) ⇒ Object
181 182 183 |
# File 'lib/stupidedi/either.rb', line 181 def fetch(default = nil) default end |
#inspect ⇒ String
256 257 258 |
# File 'lib/stupidedi/either.rb', line 256 def inspect "Either.failure(#{@reason.inspect})" end |
#or {|reason| ... } ⇒ Either
217 218 219 220 221 222 223 224 225 |
# File 'lib/stupidedi/either.rb', line 217 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) ⇒ void
This method returns an undefined value.
247 248 249 250 251 252 253 |
# File 'lib/stupidedi/either.rb', line 247 def pretty_print(q) q.text("Either.failure") q.group(2, "(", ")") do q.breakable "" q.pp @reason end end |
#reject(reason = nil) ⇒ Failure
194 195 196 |
# File 'lib/stupidedi/either.rb', line 194 def reject(reason = nil) self end |
#select(reason = nil) ⇒ Failure
189 190 191 |
# File 'lib/stupidedi/either.rb', line 189 def select(reason = nil) self end |
#tap ⇒ Object
237 238 239 |
# File 'lib/stupidedi/either.rb', line 237 def tap self end |