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.
287 288 289 290 |
# File 'lib/fast_regexp.rb', line 287 def initialize(backend, haystack) @backend = backend @string = haystack end |
Instance Attribute Details
#backend ⇒ Object (readonly)
Returns the value of attribute backend.
285 286 287 |
# File 'lib/fast_regexp.rb', line 285 def backend @backend end |
#string ⇒ Object (readonly)
Returns the value of attribute string.
285 286 287 |
# File 'lib/fast_regexp.rb', line 285 def string @string end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
318 319 320 |
# File 'lib/fast_regexp.rb', line 318 def ==(other) other.is_a?(MatchData) && to_a == other.to_a && string == other.string end |
#[](key) ⇒ Object
298 |
# File 'lib/fast_regexp.rb', line 298 def [](key) = @backend[key] |
#byte_begin(key) ⇒ Object
312 |
# File 'lib/fast_regexp.rb', line 312 def byte_begin(key) = @backend.byte_begin(key) |
#byte_end(key) ⇒ Object
313 |
# File 'lib/fast_regexp.rb', line 313 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).
311 |
# File 'lib/fast_regexp.rb', line 311 def byteoffset(key) = @backend.byteoffset(key) |
#captures ⇒ Object
300 |
# File 'lib/fast_regexp.rb', line 300 def captures = @backend.captures |
#each(&block) ⇒ Object
315 |
# File 'lib/fast_regexp.rb', line 315 def each(&block) = to_a.each(&block) |
#hash ⇒ Object
323 |
# File 'lib/fast_regexp.rb', line 323 def hash = [to_a, string].hash |
#inspect ⇒ Object
325 |
# File 'lib/fast_regexp.rb', line 325 def inspect = "#<Fast::Regexp::MatchData #{to_s.inspect}>" |
#named_captures ⇒ Object
301 |
# File 'lib/fast_regexp.rb', line 301 def named_captures = @backend.named_captures |
#names ⇒ Object
302 |
# File 'lib/fast_regexp.rb', line 302 def names = @backend.names |
#native ⇒ Object
295 |
# File 'lib/fast_regexp.rb', line 295 def native = native? ? @backend : nil |
#native? ⇒ Boolean
292 |
# File 'lib/fast_regexp.rb', line 292 def native? = @backend.is_a?(Fast::Regexp::Native::MatchData) |
#post_match ⇒ Object
306 |
# File 'lib/fast_regexp.rb', line 306 def post_match = @backend.post_match |
#pre_match ⇒ Object
305 |
# File 'lib/fast_regexp.rb', line 305 def pre_match = @backend.pre_match |
#size ⇒ Object Also known as: length
303 |
# File 'lib/fast_regexp.rb', line 303 def size = @backend.size |
#stdlib ⇒ Object
296 |
# File 'lib/fast_regexp.rb', line 296 def stdlib = stdlib? ? @backend : nil |
#stdlib? ⇒ Boolean
293 |
# File 'lib/fast_regexp.rb', line 293 def stdlib? = !native? |
#to_a ⇒ Object
299 |
# File 'lib/fast_regexp.rb', line 299 def to_a = @backend.to_a |
#to_s ⇒ Object
307 |
# File 'lib/fast_regexp.rb', line 307 def to_s = @backend.to_s |
#values_at(*indices) ⇒ Object
316 |
# File 'lib/fast_regexp.rb', line 316 def values_at(*indices) = indices.map { |i| self[i] } |