From: ChrisH Date: 2006-07-28T01:25:04+09:00 Subject: Re: rand(-10..10) Daniel Schierbeck wrote: ... > This should work with all enumerables: > > module Enumerable > def rand > entries = entries > entries.at(Kernel.rand(entries.length)) > end > end > > I can't seem to get around the `entries = entries' part -- I don't want > to convert the enumerable to an array more than once. Any ideas? Enumerable supports sort_by, so could just use: module Enumerable def rand self.sort_by{Kernel.rand}.last end end Cheers Chris