Improve Array#sample with random documentation

* array.c (rb_ary_sample): Adds examples for the use of the
  optional parameter random for Array#sample and unifies the style
  with the documentation of Array#shuffle.

[Fix GH-1825]

From: Alberto Almagro <alberto.almagro@rakuten.com>

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62553 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2018-02-24 01:12:51 +00:00
Родитель e5d5cc4a88
Коммит 623160916d
1 изменённых файлов: 5 добавлений и 2 удалений

Просмотреть файл

@ -4868,11 +4868,14 @@ rb_ary_shuffle(int argc, VALUE *argv, VALUE ary)
* If the array is empty the first form returns +nil+ and the second form * If the array is empty the first form returns +nil+ and the second form
* returns an empty array. * returns an empty array.
* *
* The optional +rng+ argument will be used as the random number generator.
*
* a = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ] * a = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]
* a.sample #=> 7 * a.sample #=> 7
* a.sample(4) #=> [6, 4, 2, 5] * a.sample(4) #=> [6, 4, 2, 5]
*
* The optional +rng+ argument will be used as the random number generator.
*
* a.sample(random: Random.new(1)) #=> 6
* a.sample(4, random: Random.new(1)) #=> [6, 10, 9, 2]
*/ */