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.
164 165 166 |
# File 'lib/stupidedi/either.rb', line 164 def initialize(reason) @reason = reason end |
Instance Attribute Details
#reason ⇒ Object (readonly)
Returns the value of attribute reason.
162 163 164 |
# File 'lib/stupidedi/either.rb', line 162 def reason @reason end |
Instance Method Details
#==(other) ⇒ Boolean
240 241 242 |
# File 'lib/stupidedi/either.rb', line 240 def ==(other) other.is_a?(self.class) and other.reason == @reason end |
#copy(changes = {}) ⇒ Failure
169 170 171 172 |
# File 'lib/stupidedi/either.rb', line 169 def copy(changes = {}) Failure.new \ changes.fetch(:reason, @reason) end |
#defined? ⇒ Boolean
Returns false.
175 176 177 |
# File 'lib/stupidedi/either.rb', line 175 def defined? false end |
#explain {|reason| ... } ⇒ Failure
228 229 230 |
# File 'lib/stupidedi/either.rb', line 228 def explain(&block) copy(:reason => deconstruct(block)) end |
#fetch(default = nil) ⇒ Object
179 180 181 |
# File 'lib/stupidedi/either.rb', line 179 def fetch(default = nil) default end |
#inspect ⇒ String
254 255 256 |
# File 'lib/stupidedi/either.rb', line 254 def inspect "Either.failure(#{@reason.inspect})" end |
#or {|reason| ... } ⇒ Either
215 216 217 218 219 220 221 222 223 |
# File 'lib/stupidedi/either.rb', line 215 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.
245 246 247 248 249 250 251 |
# File 'lib/stupidedi/either.rb', line 245 def pretty_print(q) q.text("Either.failure") q.group(2, "(", ")") do q.breakable "" q.pp @reason end end |
#reject(reason = nil) ⇒ Failure
192 193 194 |
# File 'lib/stupidedi/either.rb', line 192 def reject(reason = nil) self end |
#select(reason = nil) ⇒ Failure
187 188 189 |
# File 'lib/stupidedi/either.rb', line 187 def select(reason = nil) self end |
#tap ⇒ Object
235 236 237 |
# File 'lib/stupidedi/either.rb', line 235 def tap self end |