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

ruby-changes:56098

From: Martin <ko1@a...>
Date: Thu, 13 Jun 2019 15:40:12 +0900 (JST)
Subject: [ruby-changes:56098] Martin Drst: 7f79a86d8b (trunk): add comments to mention sort.reverse!

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

From 7f79a86d8b4d250ea0e82eb06cd3336edb840a01 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Martin=20D=C3=BCrst?= <duerst@i...>
Date: Thu, 13 Jun 2019 15:30:03 +0900
Subject: add comments to mention sort.reverse!

For array.c (Array#sort) and enum.c (Enumerable#sort_by),
add comments mentioning that sort.reverse! / sort_by { ... }.reverse!
can/should be used to reverse the result. [ci skip]

diff --git a/array.c b/array.c
index 37a6b2b..de2f808 100644
--- a/array.c
+++ b/array.c
@@ -2819,6 +2819,11 @@ rb_ary_sort_bang(VALUE ary) https://github.com/ruby/ruby/blob/trunk/array.c#L2819
  *     ary.sort                     #=> ["a", "b", "c", "d", "e"]
  *     ary.sort {|a, b| b <=> a}    #=> ["e", "d", "c", "b", "a"]
  *
+ *  To produce the reverse order, the following can also be used
+ *  (and may be faster):
+ *
+ *    ary.sort.reverse!             #=> ["e", "d", "c", "b", "a"]
+ *
  *  See also Enumerable#sort_by.
  */
 
diff --git a/enum.c b/enum.c
index 56cef17..c3a8207 100644
--- a/enum.c
+++ b/enum.c
@@ -1220,6 +1220,10 @@ sort_by_cmp(const void *ap, const void *bp, void *data) https://github.com/ruby/ruby/blob/trunk/enum.c#L1220
  *
  *     sorted = Dir["*"].sort_by { |f| test(?M, f) }
  *     sorted   #=> ["mon", "tues", "wed", "thurs"]
+ *
+ *  To produce the reverse of a specific order, the following can  be used:
+ *
+ *    ary.sort_by { ... }.reverse!
  */
 
 static VALUE
-- 
cgit v0.10.2


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

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