D
David Garamond
I'm wondering what other people's thoughts are about adding these
methods. They are found in PHP but not in Ruby at the moment. I'm not
submitting an RCR because I don't feel strongly about these myself, but
since Ruby's class library are usually "battery-included", there might
be interest to include the methods below as well. Each of these can be
implemented with a few lines of Ruby.
Array#shuffle -> nil
shuffle an array. perhaps add an argument to specify "how much" do
we want to shuffle?
Array#pick(n=1) -> anArray (method name?)
pick one or more random elements from array.
Array#pick(n=1) { |x,y,z...| } (syntax? method name?)
feed block with random element(s) from the array.
Perhaps it would be nice too if there is a random pick method with
weighting, but I cannot propose the decent syntax for it.
Array#chunk(n) -> anArray
split an array into chunks, each containing at most n elements.
Any other "useful" methods people want for Array?
methods. They are found in PHP but not in Ruby at the moment. I'm not
submitting an RCR because I don't feel strongly about these myself, but
since Ruby's class library are usually "battery-included", there might
be interest to include the methods below as well. Each of these can be
implemented with a few lines of Ruby.
Array#shuffle -> nil
shuffle an array. perhaps add an argument to specify "how much" do
we want to shuffle?
Array#pick(n=1) -> anArray (method name?)
pick one or more random elements from array.
Array#pick(n=1) { |x,y,z...| } (syntax? method name?)
feed block with random element(s) from the array.
Perhaps it would be nice too if there is a random pick method with
weighting, but I cannot propose the decent syntax for it.
Array#chunk(n) -> anArray
split an array into chunks, each containing at most n elements.
Any other "useful" methods people want for Array?