Class: Regexp

Inherits:
Object show all
Includes:
Cannonbol::Operators
Defined in:
lib/cannonbol/cannonbol.rb

Instance Method Summary collapse

Methods included from Cannonbol::Operators

#&, #_match?, #capture!, #capture?, included, #insensitive, #matches?, #|

Instance Method Details

#__match?(needle, thread_state = nil) ⇒ Boolean

Returns:

  • (Boolean)


576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
# File 'lib/cannonbol/cannonbol.rb', line 576

def __match?(needle, thread_state = nil)
  if RUBY_ENGINE == 'opal'
    options = ""
    options += "m" if `#{self}.multiline`
    options += "g" if `#{self}.global`
    options += "i" if needle.ignore_case or `#{self}.ignoreCase`
  else
    options = self.options | (needle.ignore_case ? Regexp::IGNORECASE : 0)
  end
  @cannonbol_regex ||= Regexp.new("^#{self.source}", options )
  if thread_state
    needle.pull(thread_state)
  elsif m = @cannonbol_regex.match(needle.remaining_string)
    [needle.push(m[0].length)]
  end
end