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:

>=20
> Issue #4632 has been reported by Jan Lelis.
>=20
> ----------------------------------------
> Feature #4632: Regexp instance method | for creating Regexp.unions=20
> http://redmine.ruby-lang.org/issues/4632
>=20
> Author: Jan Lelis
> Status: Open
> Priority: Normal
> Assignee:=20
> Category:=20
> Target version:=20
>=20
>=20
> Regexp.union is a great feature, but it is rarely used. I can imagine, th=
e following syntax would be quite popular:
>=20
> For example:
>  /Ruby\d/ | /test/i | "cheat" #=3D> Regexp.union( Regexp.union( /Ruby\d/,=
 /test/i ), "cheat" )
>=20
> It would also be cool as String method, so one can do:
>  "jruby" | "rbx" #=3D> /jruby|rbx/
>=20
> Example implementation:
>  class Regexp
>    def |(arg)
>      Regexp.union self, arg.is_a?(Regexp) ? arg : arg.to_s
>    end
>  end
>=20
>  class String
>    def |(arg)
>      Regexp.union self, arg.is_a?(Regexp) ? arg : arg.to_s
>    end
>  end
>=20
>=20
> --=20
> http://redmine.ruby-lang.org
>=20