Class: Mustermann::Set::Match

Inherits:
Match
  • Object
show all
Defined in:
lib/mustermann/set/match.rb

Overview

Subclass of Match that also includes the value associated with the pattern that produced the match.

Instance Attribute Summary collapse

Attributes inherited from Match

#captures, #named_captures, #params, #pattern, #post_match, #pre_match, #regexp, #string

Instance Method Summary collapse

Methods inherited from Match

#[], #deconstruct_keys, #hash, #to_s, #values_at

Constructor Details

#initialize(pattern, string, **options) ⇒ Match #initialize(match, **options) ⇒ Match #initialize(pattern, match, **options) ⇒ Match

Returns a new instance of Match.

Overloads:

  • #initialize(pattern, string, **options) ⇒ Match

    Parameters:

    • pattern (Mustermann::Pattern)

      the pattern that produced the match

    • string (String)

      the string that was matched

  • #initialize(match, **options) ⇒ Match

    Parameters:

  • #initialize(pattern, match, **options) ⇒ Match

    Parameters:

Parameters:

  • options (Hash)

    a customizable set of options



14
15
16
17
# File 'lib/mustermann/set/match.rb', line 14

def initialize(*, value: nil, **)
  @value = value
  super(*, **)
end

Instance Attribute Details

#valueObject (readonly)

Returns the value associated with the pattern that produced the match, if any.

Returns:

  • the value associated with the pattern that produced the match, if any



10
11
12
# File 'lib/mustermann/set/match.rb', line 10

def value
  @value
end

Instance Method Details

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)

See Also:



20
# File 'lib/mustermann/set/match.rb', line 20

def eql?(other) = super && value == other.value