Class: MatchData
- Inherits:
-
Object
- Object
- MatchData
- Defined in:
- documented/common/class_exts/matchdata.rb
Overview
Represents the result of a regular expression match.
This class provides methods to access the captured groups and their names.
Instance Method Summary collapse
-
#to_hash ⇒ Hash
Converts the match data to a hash with named captures as keys.
-
#to_struct ⇒ OpenStruct
Converts the match data to an OpenStruct object.
Instance Method Details
#to_hash ⇒ Hash
Converts the match data to a hash with named captures as keys.
20 21 22 23 24 |
# File 'documented/common/class_exts/matchdata.rb', line 20 def to_hash self.names.zip(self.captures.map(&:strip).map do |capture| if capture.is_i? then capture.to_i else capture end end).to_h end |
#to_struct ⇒ OpenStruct
Converts the match data to an OpenStruct object.
12 13 14 |
# File 'documented/common/class_exts/matchdata.rb', line 12 def to_struct OpenStruct.new to_hash end |