Actions
Feature #4632
closedRegexp instance method | for creating Regexp.unions
Feature #4632:
Regexp instance method | for creating Regexp.unions
Status:
Rejected
Assignee:
-
Target version:
-
Description
=begin
Regexp.union is a great feature, but it is rarely used. I can imagine, the following syntax would be quite popular:
For example:
/Ruby\d/ | /test/i | "cheat" #=> Regexp.union( Regexp.union( /Ruby\d/, /test/i ), "cheat" )
It would also be cool as String method, so one can do:
"jruby" | "rbx" #=> /jruby|rbx/
Example implementation:
class Regexp
def |(arg)
Regexp.union self, arg.is_a?(Regexp) ? arg : arg.to_s
end
end
class String
def |(arg)
Regexp.union self, arg.is_a?(Regexp) ? arg : arg.to_s
end
end
=end
Actions