mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
62e41d3f2e
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
39 lines
427 B
Ruby
39 lines
427 B
Ruby
|
|
class RegOr
|
|
def initialize(re1, re2)
|
|
@re1 = re1
|
|
@re2 = re2
|
|
end
|
|
|
|
def =~ (str)
|
|
@re1 =~ str or @re2 =~ str
|
|
end
|
|
end
|
|
|
|
class RegAnd
|
|
def initialize(re1, re2)
|
|
@re1 = re1
|
|
@re2 = re2
|
|
end
|
|
|
|
def =~ (str)
|
|
@re1 =~ str and @re2 =~ str
|
|
end
|
|
end
|
|
|
|
class Regexp
|
|
def |(other)
|
|
RegOr.new(self, other)
|
|
end
|
|
def &(other)
|
|
RegAnd.new(self, other)
|
|
end
|
|
end
|
|
|
|
p "abc" =~ /b/|/c/
|
|
p "abc" =~ /b/&/c/
|
|
|
|
|
|
|
|
|
|
|