Line | |
---|
1 | # this is just a proof of concept toy.
|
---|
2 |
|
---|
3 | class RegOr
|
---|
4 | def initialize(re1, re2)
|
---|
5 | @re1 = re1
|
---|
6 | @re2 = re2
|
---|
7 | end
|
---|
8 |
|
---|
9 | def =~ (str)
|
---|
10 | @re1 =~ str or @re2 =~ str
|
---|
11 | end
|
---|
12 | end
|
---|
13 |
|
---|
14 | class RegAnd
|
---|
15 | def initialize(re1, re2)
|
---|
16 | @re1 = re1
|
---|
17 | @re2 = re2
|
---|
18 | end
|
---|
19 |
|
---|
20 | def =~ (str)
|
---|
21 | @re1 =~ str and @re2 =~ str
|
---|
22 | end
|
---|
23 | end
|
---|
24 |
|
---|
25 | class Regexp
|
---|
26 | def |(other)
|
---|
27 | RegOr.new(self, other)
|
---|
28 | end
|
---|
29 | def &(other)
|
---|
30 | RegAnd.new(self, other)
|
---|
31 | end
|
---|
32 | end
|
---|
33 |
|
---|
34 | if __FILE__ == $0
|
---|
35 | p "abc" =~ /b/|/c/
|
---|
36 | p "abc" =~ /b/&/c/
|
---|
37 | end
|
---|
Note:
See
TracBrowser
for help on using the repository browser.