ruby-changes:2668
From: ko1@a...
Date: 9 Dec 2007 16:37:06 +0900
Subject: [ruby-changes:2668] akr - Ruby:r14159 (trunk): document named capture of MatchData#{offset,begin,end,inspect}.
akr 2007-12-09 16:35:54 +0900 (Sun, 09 Dec 2007)
New Revision: 14159
Modified files:
trunk/re.c
trunk/test/ruby/test_regexp.rb
Log:
document named capture of MatchData#{offset,begin,end,inspect}.
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/test/ruby/test_regexp.rb?r1=14159&r2=14158
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/re.c?r1=14159&r2=14158
Index: re.c
===================================================================
--- re.c (revision 14158)
+++ re.c (revision 14159)
@@ -666,6 +666,11 @@
* m = /(.)(.)(\d+)(\d)/.match("THX1138.")
* m.offset(0) #=> [1, 7]
* m.offset(4) #=> [6, 7]
+ *
+ * m = /(?<foo>.)(.)(?<bar>.)/.match("hoge")
+ * p m.offset(:foo) #=> [0, 1]
+ * p m.offset(:bar) #=> [2, 3]
+ *
*/
static VALUE
@@ -694,6 +699,10 @@
* m = /(.)(.)(\d+)(\d)/.match("THX1138.")
* m.begin(0) #=> 1
* m.begin(2) #=> 2
+ *
+ * m = /(?<foo>.)(.)(?<bar>.)/.match("hoge")
+ * p m.begin(:foo) #=> 0
+ * p m.begin(:bar) #=> 2
*/
static VALUE
@@ -721,6 +730,10 @@
* m = /(.)(.)(\d+)(\d)/.match("THX1138.")
* m.end(0) #=> 7
* m.end(2) #=> 3
+ *
+ * m = /(?<foo>.)(.)(?<bar>.)/.match("hoge")
+ * p m.end(:foo) #=> 1
+ * p m.end(:bar) #=> 3
*/
static VALUE
@@ -1284,11 +1297,15 @@
*
* Returns a printable version of <i>mtch</i>.
*
- * /.$/ =~ "foo"; puts $~.inspect
+ * puts /.$/.match("foo").inspect
* #=> #<MatchData "o">
*
- * /(.)(.)(.)/ =~ "foo"; puts $~.inspect
- * #=> #<MatchData "foo" "f" "o" "o">
+ * puts /(.)(.)(.)/.match("foo").inspect
+ * #=> #<MatchData "foo" 1:"f" 2:"o" 3:"o">
+ *
+ * puts /(?<foo>.)(?<bar>.)(?<baz>.)/.match("hoge").inspect
+ * #=> #<MatchData "hog" foo:"h" bar:"o" baz:"g">
+ *
*/
static VALUE
Index: test/ruby/test_regexp.rb
===================================================================
--- test/ruby/test_regexp.rb (revision 14158)
+++ test/ruby/test_regexp.rb (revision 14159)
@@ -57,7 +57,6 @@
assert_equal(5, m.begin(:foo))
assert_equal(8, m.end(:foo))
assert_equal([5,8], m.offset(:foo))
- #assert_equal(["amp"], m.values_at(:foo))
assert_equal("aaa [amp] yyy", "aaa & yyy".sub(/&(?<foo>.*?);/, '[\k<foo>]'))
--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml