Project

General

Profile

Feature #4632

Regexp instance method | for creating Regexp.unions

Added by rbjl (Jan Lelis) over 8 years ago. Updated over 8 years ago.

Status:
Rejected
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:35946]

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

History

Updated by rkh (Konstantin Haase) over 8 years ago

=begin
I like it for Regexp, but a string method would violate the POLS, imho.

Konstantin

On Apr 29, 2011, at 14:59 , Jan Lelis wrote:

Issue #4632 has been reported by Jan Lelis.


Feature #4632: Regexp instance method | for creating Regexp.unions
http://redmine.ruby-lang.org/issues/4632

Author: Jan Lelis
Status: Open
Priority: Normal
Assignee:
Category:
Target version:

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" #
=end

Updated by shyouhei (Shyouhei Urabe) over 8 years ago

  • Status changed from Open to Rejected

=begin
We once had this feature, eregex.rb, but dropped since 1.9. No once nursed that lib.

I don't stop you to have such tiny lib as a gem. If that gem was used widely, chances are that we might invite that as our standard again someday.
=end

Updated by rbjl (Jan Lelis) over 8 years ago

=begin
Thanks for the quick answer.
=end

Also available in: Atom PDF