Class: PatternMatching::PatternMatch
- Inherits:
-
Object
- Object
- PatternMatching::PatternMatch
- Defined in:
- lib/pattern_matching/pattern_match.rb
Overview
Encapsulates pattern matching behaviors such as deep-matching of collection types as well as wildcard values such as ‘Any`.
Instance Attribute Summary collapse
-
#pattern ⇒ Object
(also: #value)
readonly
Returns the value of attribute pattern.
Instance Method Summary collapse
-
#===(*other) ⇒ Object
As both self.pattern and other are slurped, they are guaranteed to begin as Arrays (i.e. they are enumerable).
-
#initialize(*pattern) ⇒ PatternMatch
constructor
A new instance of PatternMatch.
Constructor Details
#initialize(*pattern) ⇒ PatternMatch
Returns a new instance of PatternMatch.
10 11 12 |
# File 'lib/pattern_matching/pattern_match.rb', line 10 def initialize(*pattern) @pattern = pattern end |
Instance Attribute Details
#pattern ⇒ Object (readonly) Also known as: value
Returns the value of attribute pattern.
7 8 9 |
# File 'lib/pattern_matching/pattern_match.rb', line 7 def pattern @pattern end |
Instance Method Details
#===(*other) ⇒ Object
As both self.pattern and other are slurped, they are guaranteed to begin as Arrays (i.e. they are enumerable). Thus all matches begin by checking a match as if the values are enumerable.
18 19 20 |
# File 'lib/pattern_matching/pattern_match.rb', line 18 def ===(*other) match_enumerable(pattern, other) end |