Class: RegexpExamples::BackReferenceGroup

Inherits:
Object
  • Object
show all
Includes:
RandomResultBySample
Defined in:
lib/regexp-examples/groups.rb

Overview

This is a bit magic… We substitute backreferences with PLACEHOLDERS. These are then, later, replaced by the appropriate value. (See BackReferenceReplacer) The simplest example is /(a) 1/ - So, we temporarily treat the “result” of /1/ as being “1”. It later gets updated.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from RandomResultBySample

#random_result

Methods included from ForceLazyEnumerators

#force_if_lazy

Constructor Details

#initialize(id) ⇒ BackReferenceGroup

Returns a new instance of BackReferenceGroup.



207
208
209
# File 'lib/regexp-examples/groups.rb', line 207

def initialize(id)
  @id = id
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



206
207
208
# File 'lib/regexp-examples/groups.rb', line 206

def id
  @id
end

Instance Method Details

#resultObject



211
212
213
# File 'lib/regexp-examples/groups.rb', line 211

def result
  [GroupResult.new("__#{@id}__")]
end