mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* array.c (rb_ary_choice): Resurrect #choice. Let me think about
it for a while. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@18514 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
e65c07e98b
commit
9ba8db842e
2 changed files with 27 additions and 0 deletions
|
|
@ -1,3 +1,8 @@
|
|||
Tue Aug 12 14:53:33 2008 Akinori MUSHA <knu@iDaemons.org>
|
||||
|
||||
* array.c (rb_ary_choice): Resurrect #choice. Let me think about
|
||||
it for a while.
|
||||
|
||||
Tue Aug 12 13:57:11 2008 Akinori MUSHA <knu@iDaemons.org>
|
||||
|
||||
* misc/ruby-mode.el (ruby-imenu-create-index-in-block): Fix the
|
||||
|
|
|
|||
22
array.c
22
array.c
|
|
@ -3349,6 +3349,27 @@ rb_ary_sample(argc, argv, ary)
|
|||
}
|
||||
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* array.choice -> obj
|
||||
*
|
||||
* Choose a random element from an array. NOTE: This method will be
|
||||
* deprecated in future. Use #sample instead.
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
rb_ary_choice(ary)
|
||||
VALUE ary;
|
||||
{
|
||||
long i, j;
|
||||
|
||||
i = RARRAY(ary)->len;
|
||||
if (i == 0) return Qnil;
|
||||
j = rb_genrand_real()*i;
|
||||
return RARRAY(ary)->ptr[j];
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* ary.cycle {|obj| block }
|
||||
|
|
@ -3882,6 +3903,7 @@ Init_Array()
|
|||
rb_define_method(rb_cArray, "shuffle!", rb_ary_shuffle_bang, 0);
|
||||
rb_define_method(rb_cArray, "shuffle", rb_ary_shuffle, 0);
|
||||
rb_define_method(rb_cArray, "sample", rb_ary_sample, -1);
|
||||
rb_define_method(rb_cArray, "choice", rb_ary_choice, 0);
|
||||
rb_define_method(rb_cArray, "cycle", rb_ary_cycle, -1);
|
||||
rb_define_method(rb_cArray, "permutation", rb_ary_permutation, -1);
|
||||
rb_define_method(rb_cArray, "combination", rb_ary_combination, 1);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue