Method: Regexp#initialize

Defined in:
lib/source/ruby.rb

#initialize(regexp, options) ⇒ Regexp

call-seq:

Regexp.compile(string, ignore_case = false) -> regexp
Regexp.compile(regexp)                      -> regexp
Regexp.new(string, ignore_case = false)     -> regexp
Regexp.new(regexp)                          -> regexp

Constructs a new regular expression from pattern, which can be either a String or a Regexp (in which case that regexp’s options are propagated, and new options may not be specified). Red currently supports only the i option flag. (See class-level documentation for details.)

r1 = Regexp.new('^a-z+:\\s+\w+')            #=> /^a-z+:\s+\w+/
r2 = Regexp.new('cat', true)                #=> /cat/i
r3 = Regexp.new(r2)                         #=> /cat/i


5119
5120
5121
5122
5123
# File 'lib/source/ruby.rb', line 5119

def initialize(regexp, options)
  `switch(options){case 0:this.__options__='';break;case 1:this.__options__='i';break;case 2:this.__options__='x';break;case 3:this.__options__='ix';break;case 4:this.__options__='s';break;case 5:this.__options__='si';break;case 6:this.__options__='sx';break;case 7:this.__options__='six';break;default:this.__options__=options?'i':'';}`
  `this.__source__=regexp.__value__||regexp`
  `this.__value__=new(RegExp)(this.__source__,'m'+(/i/.test(this.__options__)?'i':''))`
end