ruby-changes:6996
From: knu <ko1@a...>
Date: Tue, 12 Aug 2008 14:56:24 +0900 (JST)
Subject: [ruby-changes:6996] Ruby:r18514 (ruby_1_8): * array.c (rb_ary_choice): Resurrect #choice. Let me think about
knu 2008-08-12 14:56:10 +0900 (Tue, 12 Aug 2008) New Revision: 18514 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=18514 Log: * array.c (rb_ary_choice): Resurrect #choice. Let me think about it for a while. Modified files: branches/ruby_1_8/ChangeLog branches/ruby_1_8/array.c Index: ruby_1_8/array.c =================================================================== --- ruby_1_8/array.c (revision 18513) +++ ruby_1_8/array.c (revision 18514) @@ -3351,6 +3351,27 @@ /* * 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 } * ary.cycle(n) {|obj| block } * @@ -3882,6 +3903,7 @@ 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); Index: ruby_1_8/ChangeLog =================================================================== --- ruby_1_8/ChangeLog (revision 18513) +++ ruby_1_8/ChangeLog (revision 18514) @@ -1,3 +1,8 @@ +Tue Aug 12 14:53:33 2008 Akinori MUSHA <knu@i...> + + * 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@i...> * misc/ruby-mode.el (ruby-imenu-create-index-in-block): Fix the -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/