Module: Corefines::String::ToRe
- Defined in:
- lib/corefines/string.rb
Instance Method Summary collapse
-
#to_re(opts = {}) ⇒ Regexp?
Returns a regular expression represented by this string.
Instance Method Details
#to_re(opts = {}) ⇒ Regexp?
Note:
This method was renamed from to_regexp to to_re due to bug
in MRI, see #11117.
Returns a regular expression represented by this string.
443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 |
# File 'lib/corefines/string.rb', line 443 module ToRe refine ::String do def to_re(opts = {}) if opts[:literal] content = ::Regexp.escape(self) elsif self =~ %r{\A/(.*)/([imxnesu]*)\z} content, inline_opts = $1, $2 content.gsub! '\\/', '/' { ignore_case: 'i', multiline: 'm', extended: 'x' }.each do |k, v| opts[k] ||= inline_opts.include? v end if inline_opts elsif opts[:detect] && !self.empty? content = ::Regexp.escape(self) else return end = 0 |= ::Regexp::IGNORECASE if opts[:ignore_case] |= ::Regexp::MULTILINE if opts[:multiline] |= ::Regexp::EXTENDED if opts[:extended] ::Regexp.new(content, ) end end end |