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

ruby-changes:51404

From: nobu <ko1@a...>
Date: Fri, 8 Jun 2018 19:45:08 +0900 (JST)
Subject: [ruby-changes:51404] nobu:r63610 (trunk): [Docs] Improve documentation of String#lines

nobu	2018-06-08 19:45:01 +0900 (Fri, 08 Jun 2018)

  New Revision: 63610

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=63610

  Log:
    [Docs] Improve documentation of String#lines
    
    * Document about optional getline arguments
    * Add examples, especially for the demonstration of `chomp: true`
    [Fix GH-1886]
    
    From: Koki Takahashi <hakatasiloving@g...>

  Modified files:
    trunk/string.c
Index: string.c
===================================================================
--- string.c	(revision 63609)
+++ string.c	(revision 63610)
@@ -8174,11 +8174,17 @@ rb_str_each_line(int argc, VALUE *argv, https://github.com/ruby/ruby/blob/trunk/string.c#L8174
 
 /*
  *  call-seq:
- *     str.lines(separator=$/)  -> an_array
+ *     str.lines(separator=$/ [, getline_args])  -> an_array
  *
  *  Returns an array of lines in <i>str</i> split using the supplied
  *  record separator (<code>$/</code> by default).  This is a
- *  shorthand for <code>str.each_line(separator).to_a</code>.
+ *  shorthand for <code>str.each_line(separator, getline_args).to_a</code>.
+ *
+ *  See IO.readlines for details about getline_args.
+ *
+ *     "hello\nworld\n".lines              #=> ["hello\n", "world\n"]
+ *     "hello  world".lines(' ')           #=> ["hello ", " ", "world"]
+ *     "hello\nworld\n".lines(chomp: true) #=> ["hello", "world"]
  *
  *  If a block is given, which is a deprecated form, works the same as
  *  <code>each_line</code>.

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

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