modalsupport 0.7.0 → 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/modalsupport/regexp.rb +9 -16
- data/lib/modalsupport/string.rb +9 -16
- data/modalsupport.gemspec +1 -1
- data/test/test_match.rb +11 -0
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.7.
|
1
|
+
0.7.1
|
data/lib/modalsupport/regexp.rb
CHANGED
@@ -1,19 +1,5 @@
|
|
1
1
|
class Regexp
|
2
2
|
|
3
|
-
if_ruby_version :<, "1.9.0" do
|
4
|
-
alias match_old match
|
5
|
-
# Modify String#match to work as in Ruby 1.9
|
6
|
-
def match(str, i=0)
|
7
|
-
str = str[i..-1] if i>0
|
8
|
-
m = self.match_old(str)
|
9
|
-
if m && block_given?
|
10
|
-
yield m
|
11
|
-
else
|
12
|
-
m
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
3
|
# Pass each match to a block: string.match_all{|match_data| ...}
|
18
4
|
def match_all(str)
|
19
5
|
result = []
|
@@ -27,8 +13,15 @@ class Regexp
|
|
27
13
|
end
|
28
14
|
|
29
15
|
# Pass the first match to a block: string.match_one{|match_data| ...}
|
30
|
-
|
31
|
-
|
16
|
+
# Similar to Ruby 1.9 match, but does not set the special varialbes $~, $1, etc. in the caller's space.
|
17
|
+
def match_one(str, i=0)
|
18
|
+
str = str[i..-1] if i>0
|
19
|
+
m = self.match(str)
|
20
|
+
if m && block_given?
|
21
|
+
yield m
|
22
|
+
else
|
23
|
+
m
|
24
|
+
end
|
32
25
|
end
|
33
26
|
|
34
27
|
end
|
data/lib/modalsupport/string.rb
CHANGED
@@ -1,19 +1,5 @@
|
|
1
1
|
class String
|
2
2
|
|
3
|
-
if_ruby_version :<, "1.9" do
|
4
|
-
alias match_old match
|
5
|
-
# Modify String#match to work as in Ruby 1.9
|
6
|
-
def match(re, i=0)
|
7
|
-
str = i>0 ? self[i..-1] : self
|
8
|
-
m = str.match_old(re)
|
9
|
-
if m && block_given?
|
10
|
-
yield m
|
11
|
-
else
|
12
|
-
m
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
3
|
# Pass each match to a block: string.match_all{|match_data| ...}; returns array of block results
|
18
4
|
def match_all(re, i=0)
|
19
5
|
result = []
|
@@ -26,8 +12,15 @@ class String
|
|
26
12
|
end
|
27
13
|
|
28
14
|
# Pass the first match to a block: string.match_one{|match_data| ...}; returns the block result
|
29
|
-
|
30
|
-
|
15
|
+
# Similar to Ruby 1.9 match, but does not set the special varialbes $~, $1, etc. in the caller's space.
|
16
|
+
def match_one(re, i=0)
|
17
|
+
str = i>0 ? self[i..-1] : self
|
18
|
+
m = str.match(re)
|
19
|
+
if m && block_given?
|
20
|
+
yield m
|
21
|
+
else
|
22
|
+
m
|
23
|
+
end
|
31
24
|
end
|
32
25
|
|
33
26
|
# For each substitution, pass the match data to a block that should return substitution value
|
data/modalsupport.gemspec
CHANGED
data/test/test_match.rb
CHANGED
@@ -27,4 +27,15 @@ class TestMatch < Test::Unit::TestCase
|
|
27
27
|
|
28
28
|
end
|
29
29
|
|
30
|
+
context "Using the stdlib match method" do
|
31
|
+
|
32
|
+
should "not be altered by this library" do
|
33
|
+
/a(x+)b/.match("axxxb")
|
34
|
+
assert_equal "xxx", $1
|
35
|
+
"axxxxb".match(/a(x+)b/)
|
36
|
+
assert_equal "xxxx", $1
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
30
41
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: modalsupport
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 1
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 7
|
9
|
-
-
|
10
|
-
version: 0.7.
|
9
|
+
- 1
|
10
|
+
version: 0.7.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Javier Goizueta
|