Class: Regex::MatchOption

Inherits:
MonadicExpression show all
Defined in:
lib/regex/match_option.rb

Overview

Represents a set of options that influences the way a regular (sub)expression can perform its matching.

Instance Attribute Summary collapse

Attributes inherited from MonadicExpression

#child

Attributes inherited from Expression

#begin_anchor, #end_anchor

Instance Method Summary collapse

Methods inherited from MonadicExpression

#done!, #lazy!

Methods inherited from CompoundExpression

#atomic?

Methods inherited from Expression

#atomic?, #options, #to_str

Constructor Details

#initialize(theChild, theFlags) ⇒ MatchOption

Constructor.

Parameters:

  • theChild (Regex::Expression)

    Child expression on which options apply.

  • theFlags (Array)

    An array of Regexp options



15
16
17
18
# File 'lib/regex/match_option.rb', line 15

def initialize(theChild, theFlags)
  super(theChild)
  @flags = theFlags
end

Instance Attribute Details

#flagsArray (readonly)

Returns Array of Regexp flags.

Returns:

  • (Array)

    Array of Regexp flags



10
11
12
# File 'lib/regex/match_option.rb', line 10

def flags
  @flags
end

Instance Method Details

#==(other) ⇒ Object

Equality operator

Parameters:



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/regex/match_option.rb', line 32

def ==(other)
  return true if object_id == other.object_id

  if other.kind_of?(MatchOption)
    isEqual = ((flags == other.flags) && (child == other.child))
  else
    isEqual = false
  end

  return isEqual
end

#combine_optsObject

Combine all options/flags into one integer value that is compliant as second argument of with Regexp#new method. return [Integer]



23
24
25
26
27
28
# File 'lib/regex/match_option.rb', line 23

def combine_opts
  result = 0
  flags.each { |f| result |= f }

  return result
end