[前][次][番号順一覧][スレッド一覧]

ruby-changes:72250

From: Nobuyoshi <ko1@a...>
Date: Mon, 20 Jun 2022 18:42:33 +0900 (JST)
Subject: [ruby-changes:72250] 7f8a915715 (master): [DOC] Refine Regexp.new argument descriptions

https://git.ruby-lang.org/ruby.git/commit/?id=7f8a915715

From 7f8a91571561206e880909461b063753e7e01d7e Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Mon, 20 Jun 2022 12:53:41 +0900
Subject: [DOC] Refine Regexp.new argument descriptions

---
 re.c | 25 +++++++++++++++++++------
 1 file changed, 19 insertions(+), 6 deletions(-)

diff --git a/re.c b/re.c
index 04dfe9dd03..e9bcf11b31 100644
--- a/re.c
+++ b/re.c
@@ -3633,7 +3633,7 @@ rb_reg_match_p(VALUE re, VALUE str, long pos) https://github.com/ruby/ruby/blob/trunk/re.c#L3633
 
 /*
  *  call-seq:
- *    Regexp.new(string, options = 0, encoding = nil, timeout: nil) -> regexp
+ *    Regexp.new(string, options = 0, n_flag = nil, timeout: nil) -> regexp
  *    Regexp.new(regexp, timeout: nil) -> regexp
  *
  *  With argument +string+ given, returns a new regexp with the given string
@@ -3656,16 +3656,29 @@ rb_reg_match_p(VALUE re, VALUE str, long pos) https://github.com/ruby/ruby/blob/trunk/re.c#L3656
  *
  *  - +nil+ or +false+, which is ignored.
  *
- *  If optional argument +encoding+ is a string starts with
- *  <code>'n'</code>, the encoding of +string+ is ignored and the new
- *  regexp encoding is fixed to +ASCII_8BIT+.
+ *  If optional argument +n_flag+ if it is a string starts with
+ *  <code>'n'</code> or <code>'N'</code>, the encoding of +string+ is
+ *  ignored and the new regexp encoding is fixed to +ASCII-8BIT+ or
+ *  +US-ASCII+, by its content.
+ *
+ *      Regexp.new('foo', nil, 'n')     # => /foo/n
+ *      Regexp.new("\u3042", nil, 'n')  # => /\xE3\x81\x82/n
  *
  *  If optional keyword argument +timeout+ is given,
  *  its float value overrides the timeout interval for the class,
  *  Regexp.timeout.
  *
- *  With argument +regexp+ given, returns a new regexp
- *  source, options, and timeout are the same as +self+.
+ *  With argument +regexp+ given, returns a new regexp. The source,
+ *  options, timeout are the same as +regexp+. +options+ and +n_flag+
+ *  arguments are ineffective.  The timeout can be overridden by
+ *  +timeout+ keyword.
+ *
+ *      options = Regexp::MULTILINE
+ *      r = Regexp.new('foo', optinos, timeout: 1.1) # => /foo/m
+ *      r2 = Regexp.new(r)                           # => /foo/m
+ *      r2.timeout                                   # => 1.1
+ *      r3 = Regexp.new(r, timeout: 3.14)            # => /foo/m
+ *      r3.timeout                                   # => 3.14
  *
  *  Regexp.compile is an alias for Regexp.new.
  *
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]