Class: RegexpExamples::CharGroup

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

Overview

The most generic type of group, which contains 0 or more characters. Technically, this is the ONLY type of group that is truly necessary However, having others both improves performance through various optimisations, and clarifies the code’s intention. The most common example of CharGroups is: /[abc]/

Instance Attribute Summary

Attributes included from GroupWithIgnoreCase

#ignorecase

Instance Method Summary collapse

Methods included from RandomResultBySample

#random_result

Methods included from ForceLazyEnumerators

#force_if_lazy

Constructor Details

#initialize(chars, ignorecase) ⇒ CharGroup

Returns a new instance of CharGroup.



95
96
97
98
# File 'lib/regexp-examples/groups.rb', line 95

def initialize(chars, ignorecase)
  @chars = chars
  @ignorecase = ignorecase
end

Instance Method Details

#resultObject



100
101
102
103
104
# File 'lib/regexp-examples/groups.rb', line 100

def result
  @chars.lazy.map do |result|
    GroupResult.new(result)
  end
end