From: "David A. Black" Date: 2008-08-02T22:13:22+09:00 Subject: [ruby-core:18081] Re: New array methods cycle, choice, shuffle (plus bug in cycle) Hi -- On Sat, 2 Aug 2008, Yukihiro Matsumoto wrote: > Hi, > > In message "Re: [ruby-core:18074] Re: New array methods cycle, choice, shuffle (plus bug in cycle)" > on Sat, 2 Aug 2008 06:43:56 +0900, David Flanagan writes: > > |If we agree that there is a use-case for adding #sample to the API, then > |I would also argue again for #sample! which removes the sampled elements > |from the array. There is no way to write #sample! based on #sample and > |I'd imagine that it would be usefule. > | > |If the method doesn't take an argument and always returns a single > |element, then I'd prefer #rand or #random_element (or just removing the > |method) to #choose or #sample. > > Here are choices: > > * Array#rand (or random, or random_element): pick one random element > from an array. some might confuse the method to behave like > #shuffle though. > > * Array#sample: this method can take an optional argument for element > number. Like #first, the method returns an array if an argument is > given. > > * Array#choice: keep the current method. We already have some > noun-named methods, e.g. first. This method can also be extended to > take an optional argument. > > Perhaps we should do vote on those candidates. Should we set up > voting site for method names? Sure, but please be a benevolent dictator and get rid of "choice" :-) The problem with it is that the name doesn't express what the method does. David -- Rails training from David A. Black and Ruby Power and Light: * Advancing With Rails August 18-21 Edison, NJ * Co-taught by D.A. Black and Erik Kastner See http://www.rubypal.com for details and updates!