From: Benoit Daloze Date: 2011-01-12T03:14:02+09:00 Subject: [ruby-core:34373] Re: [Ruby 1.9-Feature#4247][Open] New features for Array#sample, Array#choice On 11 January 2011 14:39, Yusuke ENDOH wrote: > Hi, > > 2011/1/8 Benoit Daloze : > You have a misunderstanding. �Array#sample already supports optional > argument to specify the count of elements sampled. �This is not a new > behavior. > > �$ ruby -ve 'p [1, 2, 3].sample(2)' > �ruby 1.9.2p0 (2010-08-18 revision 29036) [i686-linux] > �[2, 1] > > Unfortunately, this behavior is included in 1.9.2 which is already > released. �It can no longer change. Sorry about that, I just missed it. I take notice to look ri whenever I speak of a method on #ruby-core. >> So here is my proposition: >> Array#sample remains unchanged. >> Array#samples is like the proposed #each_sample, with the option >> :repeat to use replacement. > > Though I'm not against your proposition, it may be a bit confusing > because Array#sample may also return some elements. Yes, I did not have that in mind, but I still prefer #samples to #each_sample. So, this is close to the original proposition, except using "repeat: true" instead of *choice and renaming #each_sample to #samples. It might be confusing, but I think the general usage with chaining enumerators will be nicer: ary.samples.map { ... } vs ary.each_sample.map { ... } I do not like using #each_slice in a chain for this reason. But if people think it is too confusing, then let #each_sample be.