Class: Fast::Regexp::MatchData

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#backendObject (readonly)

Returns the value of attribute backend.



285
286
287
# File 'lib/fast_regexp.rb', line 285

def backend
  @backend
end

#stringObject (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)

#capturesObject



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)

#hashObject



323
# File 'lib/fast_regexp.rb', line 323

def hash = [to_a, string].hash

#inspectObject



325
# File 'lib/fast_regexp.rb', line 325

def inspect = "#<Fast::Regexp::MatchData #{to_s.inspect}>"

#named_capturesObject



301
# File 'lib/fast_regexp.rb', line 301

def named_captures = @backend.named_captures

#namesObject



302
# File 'lib/fast_regexp.rb', line 302

def names = @backend.names

#nativeObject



295
# File 'lib/fast_regexp.rb', line 295

def native = native? ? @backend : nil

#native?Boolean

Returns:

  • (Boolean)


292
# File 'lib/fast_regexp.rb', line 292

def native? = @backend.is_a?(Fast::Regexp::Native::MatchData)

#post_matchObject



306
# File 'lib/fast_regexp.rb', line 306

def post_match = @backend.post_match

#pre_matchObject



305
# File 'lib/fast_regexp.rb', line 305

def pre_match = @backend.pre_match

#sizeObject Also known as: length



303
# File 'lib/fast_regexp.rb', line 303

def size = @backend.size

#stdlibObject



296
# File 'lib/fast_regexp.rb', line 296

def stdlib = stdlib? ? @backend : nil

#stdlib?Boolean

Returns:

  • (Boolean)


293
# File 'lib/fast_regexp.rb', line 293

def stdlib? = !native?

#to_aObject



299
# File 'lib/fast_regexp.rb', line 299

def to_a = @backend.to_a

#to_sObject



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] }