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 “BACKREF-PLACEHOLDER-1”. It later gets updated.

Constant Summary collapse

PLACEHOLDER_FORMAT =
'__BACKREF-PLACEHOLDER-%s__'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from RandomResultBySample

#random_result

Constructor Details

#initialize(id) ⇒ BackReferenceGroup

Returns a new instance of BackReferenceGroup.



189
190
191
# File 'lib/regexp-examples/groups.rb', line 189

def initialize(id)
  @id = id
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



188
189
190
# File 'lib/regexp-examples/groups.rb', line 188

def id
  @id
end

Instance Method Details

#resultObject



193
194
195
# File 'lib/regexp-examples/groups.rb', line 193

def result
  [GroupResult.new(PLACEHOLDER_FORMAT % @id)]
end