Class: MonadOxide::Either
- Inherits:
-
Object
- Object
- MonadOxide::Either
- Defined in:
- lib/either.rb
Instance Method Summary collapse
-
#initialize(_data) ⇒ Either
constructor
A new instance of Either.
-
#match(matcher) ⇒ R
Use pattern matching to work with both Left and Right variants.
Constructor Details
#initialize(_data) ⇒ Either
Returns a new instance of Either.
47 48 49 |
# File 'lib/either.rb', line 47 def initialize(_data) raise NoMethodError.new('Do not use Either directly. See Left and Right.') end |
Instance Method Details
#match(matcher) ⇒ R
Use pattern matching to work with both Left and Right variants. This is useful when it is desirable to have both variants handled in the same location. It can also be useful when either variant can coerced into a non-Result type.
Ruby has no built-in pattern matching, but the next best thing is a Hash using the Either classes themselves as the keys.
Tests for this are found in the tests of the Left and Right classes.
upon.
67 68 69 |
# File 'lib/either.rb', line 67 def match(matcher) matcher[self.class()].call(@data) end |