From: Jon Olson Date: 2007-09-07T10:13:55+09:00 Subject: Re: New array methods cycle, choice, shuffle (plus bug in cycle) On Sep 6, 2007, at 6:11 PM, David Flanagan wrote: > Four new methods have been added to Array the Ruby 1.9 trunk. I've > got a couple of questions and comments and one bug report: > > > choice returns a random element from the array. I don't like the > name of this method: neither the word "choice" nor it verb form > "choose" imply randomness--instead they suggest the opposite. I > suggest just using the name "rand", "random" or "random_element". > Most array methods are verbs, but a noun here would match the > existing methods first and last. Also, may I suggest a random! > variant of the method that returns *and removes* a random element > from the array? first and last already have shift and pop to serve > this purpose. > Choose seems like a reasonable name if you consider it in a combinatorial sense (i.e., 6 choose 2 for 6!/(4!2!)). With that meaning though, it makes sense for this method to take an optional parameter indicating the number of elements to select, defaulting to nil. It could return the element itself in this case or a single element array when called with the number 1. -- Jon Olson