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.



256
257
258
259
# File 'lib/fast_regexp.rb', line 256

def initialize(backend, haystack)
  @backend = backend
  @string = haystack
end

Instance Attribute Details

#backendObject (readonly)

Returns the value of attribute backend.



254
255
256
# File 'lib/fast_regexp.rb', line 254

def backend
  @backend
end

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

#capturesObject



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)

#hashObject



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

def hash = [to_a, string].hash

#inspectObject



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

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

#named_capturesObject



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

def named_captures = @backend.named_captures

#namesObject



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

def names = @backend.names

#nativeObject



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

def native = native? ? @backend : nil

#native?Boolean

Returns:

  • (Boolean)


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

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

#post_matchObject



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

def post_match = @backend.post_match

#pre_matchObject



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

def pre_match = @backend.pre_match

#sizeObject Also known as: length



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

def size = @backend.size

#stdlibObject



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

def stdlib = stdlib? ? @backend : nil

#stdlib?Boolean

Returns:

  • (Boolean)


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

def stdlib? = !native?

#to_aObject



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

def to_a = @backend.to_a

#to_sObject



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