Module: Llull::PatternMatching
- Included in:
- Result
- Defined in:
- lib/llull/pattern_matching.rb
Overview
Pattern matching functionality for Result instances
Instance Method Summary collapse
-
#deconstruct ⇒ Array
Pattern matching support for Ruby 3+ (array-style).
-
#deconstruct_keys(_keys) ⇒ Hash
Pattern matching support for Ruby 3+ (hash-style).
-
#match(&block) ⇒ Object
Advanced pattern matching with DSL.
Instance Method Details
#deconstruct ⇒ Array
Pattern matching support for Ruby 3+ (array-style)
8 9 10 |
# File 'lib/llull/pattern_matching.rb', line 8 def deconstruct success? ? [:success, value] : [:failure, error_type, error_data] end |
#deconstruct_keys(_keys) ⇒ Hash
Pattern matching support for Ruby 3+ (hash-style)
15 16 17 18 19 20 21 |
# File 'lib/llull/pattern_matching.rb', line 15 def deconstruct_keys(_keys) if success? { success: true, value: value } else { success: false, error_type: error_type, error_data: error_data } end end |
#match(&block) ⇒ Object
Advanced pattern matching with DSL
26 27 28 29 30 |
# File 'lib/llull/pattern_matching.rb', line 26 def match(&block) matcher = Matcher.new(self) block.call(matcher) matcher.execute end |