Class: Decoding::Decoders::Match
- Inherits:
-
Decoding::Decoder
- Object
- Decoding::Decoder
- Decoding::Decoders::Match
- Defined in:
- lib/decoding/decoders/match.rb
Overview
Decoder that matches values using the === operator. This will work with
regular expressions or classes.
Instance Method Summary collapse
- #call(value) ⇒ Decoding::Result<a>
-
#initialize(pattern) ⇒ Match
constructor
A new instance of Match.
Methods inherited from Decoding::Decoder
Constructor Details
#initialize(pattern) ⇒ Match
Returns a new instance of Match.
11 12 13 14 |
# File 'lib/decoding/decoders/match.rb', line 11 def initialize(pattern) @pattern = pattern super() end |
Instance Method Details
#call(value) ⇒ Decoding::Result<a>
18 19 20 21 22 23 24 25 26 |
# File 'lib/decoding/decoders/match.rb', line 18 def call(value) if @pattern === value ok(value) elsif @pattern.is_a?(Class) err(failure("expected #{@pattern}, got #{value.class}")) else err(failure("expected value matching #{@pattern.inspect}, got: #{value.inspect}")) end end |