summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/rbot/core/utils/extends.rb18
1 files changed, 18 insertions, 0 deletions
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