class RuboCop::AST::RegexpNode

to all ‘regexp` nodes within RuboCop.
node when the builder constructs the AST, making its methods available
A node extension for `regexp` nodes. This will be used in place of a plain

def content

Returns:
  • (String) - a string of regexp content
def content
  children.select(&:str_type?).map(&:str_content).join
end

def delimiter?(char)

Returns:
  • (Bool) - if char is one of the delimiters
def delimiter?(char)
  delimiters.include?(char)
end

def delimiters

Returns:
  • (String) - the regexp delimiters (without %r)
def delimiters
  [loc.begin.source[-1], loc.end.source[0]]
end

def extended?

Returns:
  • (Bool) - if regexp uses the extended regopt
def extended?
  regopt_include?(:x)
end

def fixed_encoding?

Returns:
  • (Bool) - if regexp uses the fixed-encoding regopt
def fixed_encoding?
  regopt_include?(:u)
end

def ignore_case?

Returns:
  • (Bool) - if regexp uses the ignore-case regopt
def ignore_case?
  regopt_include?(:i)
end

def interpolation?

Returns:
  • (Bool) - if regexp contains interpolation
def interpolation?
  children.any?(&:begin_type?)
end

def multiline_mode?

Returns:
  • (Bool) - if regexp uses the multiline regopt
def multiline_mode?
  regopt_include?(:m)
end

def no_encoding?

Returns:
  • (Bool) - if regexp uses the no-encoding regopt
def no_encoding?
  regopt_include?(:n)
end

def options

Returns:
  • (Integer) - the Regexp option bits as returned by Regexp#options
def options
  regopt.children.map { |opt| OPTIONS.fetch(opt) }.inject(0, :|)
end

def percent_r_literal?

Returns:
  • (Bool) - if the regexp is a %r{...} literal (using any delimiters)
def percent_r_literal?
  !slash_literal?
end

def regopt

Returns:
  • (RuboCop::AST::Node) - a regopt node
def regopt
  children.last
end

def regopt_include?(option)

def regopt_include?(option)
  regopt.children.include?(option)
end

def single_interpolation?

Returns:
  • (Bool) - if regexp uses the single-interpolation regopt
def single_interpolation?
  regopt_include?(:o)
end

def slash_literal?

Returns:
  • (Bool) - if the regexp is a /.../ literal
def slash_literal?
  loc.begin.source == '/'
end

def to_regexp

Returns:
  • (Regexp) - a regexp of this node
def to_regexp
  Regexp.new(content, options)
end