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 CHANGED
@@ -1 +1 @@
1
- 0.7.0
1
+ 0.7.1
@@ -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
- def match_one(str, i=0, &blk)
31
- match str, i, &blk
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
@@ -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
- def match_one(re, i=0, &blk)
30
- match re, i, &blk
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
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{modalsupport}
8
- s.version = "0.7.0"
8
+ s.version = "0.7.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Javier Goizueta"]
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: 3
4
+ hash: 1
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 7
9
- - 0
10
- version: 0.7.0
9
+ - 1
10
+ version: 0.7.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Javier Goizueta