From: Intransition Date: 2012-06-26T04:59:23+09:00 Subject: Re: Array#sample is Set#sample and not Array#sample ! ------=_Part_93_23698046.1340654361617 Content-Type: multipart/alternative; boundary="----=_Part_94_1960133.1340654361617" ------=_Part_94_1960133.1340654361617 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On Monday, June 25, 2012 10:53:51 AM UTC-4, Michel Demazure wrote: > > Arrays are ordered, sets are not. Sampling an array should give random > elements in the good order. But : > > irb(main):001:0> (0..10).to_a.sample(5) > => [8, 10, 4, 6, 7] > > Today's Array#sample actually is Set#sample, but Set#sample does not > exist. > > irb(main):002:0> Set.new((0..10)).sample(5) > NoMethodError: undefined method `sample' for # 6, 7, 8, 9, 10}> > I think that would require a different method, say #ordered_sample. If you write it and I'll add it to Facets random.rb. ------=_Part_94_1960133.1340654361617 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 7bit

On Monday, June 25, 2012 10:53:51 AM UTC-4, Michel Demazure wrote:
Arrays are ordered, sets are not. Sampling an array should give random
elements in the good order. But :

irb(main):001:0> (0..10).to_a.sample(5)
=> [8, 10, 4, 6, 7]

Today's Array#sample actually is Set#sample, but Set#sample does not
exist.

irb(main):002:0> Set.new((0..10)).sample(5)
NoMethodError: undefined method `sample' for #<Set: {0, 1, 2, 3, 4, 5,
6, 7, 8, 9, 10}>

I think that would require a different method, say #ordered_sample.

If you write it and I'll add it to Facets random.rb.

------=_Part_94_1960133.1340654361617-- ------=_Part_93_23698046.1340654361617--