From 3220c8e65e723790dfd69e05c012ad78badfbb45 Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Wed, 9 Apr 2008 00:28:18 +0200 Subject: [PATCH] extends: Array#shuffle! and shuffle methods --- lib/rbot/core/utils/extends.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib/rbot/core/utils/extends.rb b/lib/rbot/core/utils/extends.rb index f3861745..19157009 100644 --- a/lib/rbot/core/utils/extends.rb +++ b/lib/rbot/core/utils/extends.rb @@ -109,6 +109,24 @@ class ::Array end self.delete_at(index) end + + # This method shuffles the items in the array + def shuffle! + base = self.dup + self.clear + while item = base.delete_one + self << item + end + self + end + + # This method returns a new array with the same items as + # the receiver, but shuffled + def shuffle + ret = self.dup + ret.shuffle! + end + end # Extensions to the Range class -- 2.32.0.93.g670b81a890