Class: MatchData
- Inherits:
-
Object
- Object
- MatchData
- Defined in:
- lib/common/class_exts/matchdata.rb
Overview
extension to class MatchData 2025-03-14
Instance Method Summary collapse
-
#to_hash ⇒ Hash
Converts the MatchData object to a hash.
-
#to_struct ⇒ OpenStruct
Converts the MatchData object to an OpenStruct.
Instance Method Details
#to_hash ⇒ Hash
Note:
This method strips whitespace from each capture and converts numeric captures to integers.
Converts the MatchData object to a hash.
28 29 30 31 32 |
# File 'lib/common/class_exts/matchdata.rb', line 28 def to_hash Hash[self.names.zip(self.captures.map(&:strip).map do |capture| if capture.is_i? then capture.to_i else capture end end)] end |
#to_struct ⇒ OpenStruct
Converts the MatchData object to an OpenStruct.
12 13 14 |
# File 'lib/common/class_exts/matchdata.rb', line 12 def to_struct OpenStruct.new to_hash end |