14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/ruby3_backward_compatibility/compatibility/regexp.rb', line 14
def new(regexp_or_string, options = NOT_GIVEN, n_flag = NOT_GIVEN, **kwargs)
if options == NOT_GIVEN
super(regexp_or_string, **kwargs)
elsif n_flag == 'n' || n_flag == 'N'
unless options.is_a?(Integer)
if RUBY_VERSION < '3.3' && options.is_a?(String) && options =~ LEGITIMATE_FLAGS
new_options = 0
new_options |= Regexp::MULTILINE if options.include?('m')
new_options |= Regexp::IGNORECASE if options.include?('i')
new_options |= Regexp::EXTENDED if options.include?('x')
options = new_options
else
options = options ? Regexp::IGNORECASE : 0
end
end
super(regexp_or_string, options | Regexp::NOENCODING, **kwargs)
elsif options.is_a?(String)
if options =~ LEGITIMATE_FLAGS && n_flag == NOT_GIVEN
super(regexp_or_string, options, **kwargs)
else
super(regexp_or_string, true, **kwargs)
end
else
super(regexp_or_string, options, **kwargs)
end
end
|