Class: Fast::Regexp::MatchData
- Inherits:
-
Object
- Object
- Fast::Regexp::MatchData
- Includes:
- Enumerable
- Defined in:
- lib/fast_regexp.rb
Overview
Wraps either a Fast::Regexp::Native::MatchData or a stdlib ::MatchData so callers see one type regardless of which backend ran.
Instance Attribute Summary collapse
-
#backend ⇒ Object
readonly
Returns the value of attribute backend.
-
#string ⇒ Object
readonly
Returns the value of attribute string.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #[](key) ⇒ Object
- #byte_begin(key) ⇒ Object
- #byte_end(key) ⇒ Object
-
#byteoffset(key) ⇒ Object
Byte-based offsets.
- #captures ⇒ Object
- #each(&block) ⇒ Object
- #hash ⇒ Object
-
#initialize(backend, haystack) ⇒ MatchData
constructor
A new instance of MatchData.
- #inspect ⇒ Object
- #named_captures ⇒ Object
- #names ⇒ Object
- #native ⇒ Object
- #native? ⇒ Boolean
- #post_match ⇒ Object
- #pre_match ⇒ Object
- #size ⇒ Object (also: #length)
- #stdlib ⇒ Object
- #stdlib? ⇒ Boolean
- #to_a ⇒ Object
- #to_s ⇒ Object
- #values_at(*indices) ⇒ Object
Constructor Details
#initialize(backend, haystack) ⇒ MatchData
Returns a new instance of MatchData.
256 257 258 259 |
# File 'lib/fast_regexp.rb', line 256 def initialize(backend, haystack) @backend = backend @string = haystack end |
Instance Attribute Details
#backend ⇒ Object (readonly)
Returns the value of attribute backend.
254 255 256 |
# File 'lib/fast_regexp.rb', line 254 def backend @backend end |
#string ⇒ Object (readonly)
Returns the value of attribute string.
254 255 256 |
# File 'lib/fast_regexp.rb', line 254 def string @string end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
287 288 289 |
# File 'lib/fast_regexp.rb', line 287 def ==(other) other.is_a?(MatchData) && to_a == other.to_a && string == other.string end |
#[](key) ⇒ Object
267 |
# File 'lib/fast_regexp.rb', line 267 def [](key) = @backend[key] |
#byte_begin(key) ⇒ Object
281 |
# File 'lib/fast_regexp.rb', line 281 def byte_begin(key) = @backend.byte_begin(key) |
#byte_end(key) ⇒ Object
282 |
# File 'lib/fast_regexp.rb', line 282 def byte_end(key) = @backend.byte_end(key) |
#byteoffset(key) ⇒ Object
Byte-based offsets. Both backends expose these (stdlib MatchData has ‘byteoffset` / `byte_begin` / `byte_end` since Ruby 3.2).
280 |
# File 'lib/fast_regexp.rb', line 280 def byteoffset(key) = @backend.byteoffset(key) |
#captures ⇒ Object
269 |
# File 'lib/fast_regexp.rb', line 269 def captures = @backend.captures |
#each(&block) ⇒ Object
284 |
# File 'lib/fast_regexp.rb', line 284 def each(&block) = to_a.each(&block) |
#hash ⇒ Object
292 |
# File 'lib/fast_regexp.rb', line 292 def hash = [to_a, string].hash |
#inspect ⇒ Object
294 |
# File 'lib/fast_regexp.rb', line 294 def inspect = "#<Fast::Regexp::MatchData #{to_s.inspect}>" |
#named_captures ⇒ Object
270 |
# File 'lib/fast_regexp.rb', line 270 def named_captures = @backend.named_captures |
#names ⇒ Object
271 |
# File 'lib/fast_regexp.rb', line 271 def names = @backend.names |
#native ⇒ Object
264 |
# File 'lib/fast_regexp.rb', line 264 def native = native? ? @backend : nil |
#native? ⇒ Boolean
261 |
# File 'lib/fast_regexp.rb', line 261 def native? = @backend.is_a?(Fast::Regexp::Native::MatchData) |
#post_match ⇒ Object
275 |
# File 'lib/fast_regexp.rb', line 275 def post_match = @backend.post_match |
#pre_match ⇒ Object
274 |
# File 'lib/fast_regexp.rb', line 274 def pre_match = @backend.pre_match |
#size ⇒ Object Also known as: length
272 |
# File 'lib/fast_regexp.rb', line 272 def size = @backend.size |
#stdlib ⇒ Object
265 |
# File 'lib/fast_regexp.rb', line 265 def stdlib = stdlib? ? @backend : nil |
#stdlib? ⇒ Boolean
262 |
# File 'lib/fast_regexp.rb', line 262 def stdlib? = !native? |
#to_a ⇒ Object
268 |
# File 'lib/fast_regexp.rb', line 268 def to_a = @backend.to_a |
#to_s ⇒ Object
276 |
# File 'lib/fast_regexp.rb', line 276 def to_s = @backend.to_s |
#values_at(*indices) ⇒ Object
285 |
# File 'lib/fast_regexp.rb', line 285 def values_at(*indices) = indices.map { |i| self[i] } |