randomly each : Enumerable « Collections « Ruby
- Ruby
- Collections
- Enumerable
randomly each
module Enumerable
def each_randomly
(sort_by { rand }).each { |e| yield e }
end
end
%w{A b c }.each_randomly { |x| puts x }
Related examples in the same category