summaryrefslogtreecommitdiff
path: root/re.c
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-12-09 07:35:54 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-12-09 07:35:54 +0000
commit7a7c26be7328099b4b2ba57ba9547e20080e071f (patch)
tree6c84ad683c0217a51f2ae66a7b9c1a6040bcecad /re.c
parent18d8fbac5484411bc7194c408edf0a3e17ea640d (diff)
document named capture of MatchData#{offset,begin,end,inspect}.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14159 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 're.c')
-rw-r--r--re.c23
1 files changed, 20 insertions, 3 deletions
diff --git a/re.c b/re.c
index e513c2ca17..1264733f6b 100644
--- a/re.c
+++ b/re.c
@@ -666,6 +666,11 @@ match_backref_number(VALUE match, VALUE backref)
* 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 @@ match_offset(VALUE match, VALUE n)
* 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 @@ match_begin(VALUE match, VALUE n)
* 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 @@ match_inspect_name_iter(const OnigUChar *name, const OnigUChar *name_end,
*
* 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