Class: RegexpExamples::BackReferenceGroup
- Inherits:
-
Object
- Object
- RegexpExamples::BackReferenceGroup
- 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
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Instance Method Summary collapse
-
#initialize(id) ⇒ BackReferenceGroup
constructor
A new instance of BackReferenceGroup.
- #result ⇒ Object
Methods included from RandomResultBySample
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
#id ⇒ Object (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
#result ⇒ Object
193 194 195 |
# File 'lib/regexp-examples/groups.rb', line 193 def result [GroupResult.new(PLACEHOLDER_FORMAT % @id)] end |