From: Matthew Smillie Date: 2006-06-20T03:06:53+09:00 Subject: Re: Is it more convenient to have a random_each in ruby stdlib? >> Though this still relies on Array#shuffle!, which I can't say is a >> good or bad thing. > > Since #shuffle! would alter the receiver, it shouldn't be defined > in Enumerable. Other ordered collections could implement their own > versions. I agree with you there, but it's not quite what I meant. More clearly, Enumerable#entries returns an array with no guarantees about the ordering. Enumerable#sort and #shuffle return similar arrays, but include guarantees about the ordering. Enumerable#shuffle uses Array#shuffle! internally to produce the final array, which just doesn't quite click for me. It's just an aesthetic disagreement, and I can't quite put my finger on anything concrete. > I was wondering, is Ruby's internal variable "switching" faster > than using a temperary variable? #shuffle! can be written like > this, but I don't know if it's faster. My hunch is that even if we could reliably measure a difference in a benchmark, it would disappear into the static in a practical system. At least, I'd hope that's the case - one being significantly faster than the other would set off some alarm bells for me about Ruby's implementation. matthew smillie.