Module: RegexConcat
- Defined in:
- lib/regex_concat.rb,
lib/regex_concat/version.rb
Constant Summary collapse
- VERSION =
"1.1.0"
Instance Method Summary collapse
-
#concat(*regexes) ⇒ Object
Concatenates Regexp objects together into a new Regexp object.
Instance Method Details
#concat(*regexes) ⇒ Object
Concatenates Regexp objects together into a new Regexp object. Keeps any flags, and adds them together. //i + //m == //im
Regexp.concat(/foo/, /bar/) # => /foobar/
Regexp.concat(/foo/i, /bar/) # => /foobar/i
Regexp.concat(/foo/ix, /bar/m) # => /foobar/mix
10 11 12 13 14 |
# File 'lib/regex_concat.rb', line 10 def concat(*regexes) allflags = regexes.inject(0) { |flags, re| flags | re. } patterns = regexes.map { |re| re.source } Regexp.new(patterns.join, allflags) end |