From 2327431c922faba63817bff7353290ba3b7cbcf4 Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Sun, 4 Nov 2007 15:11:09 +0000 Subject: extends: Arraydata/rbot/plugins/factoids.rbdelete_one to remove a random element from an array --- lib/rbot/core/utils/extends.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'lib/rbot') diff --git a/lib/rbot/core/utils/extends.rb b/lib/rbot/core/utils/extends.rb index 7b733994..e587f564 100644 --- a/lib/rbot/core/utils/extends.rb +++ b/lib/rbot/core/utils/extends.rb @@ -49,6 +49,14 @@ class ::Array return nil if self.empty? self[rand(self.length)] end + + # This method returns a random element from the array, deleting it from the + # array itself. The method returns nil if the array is empty + # + def delete_one + return nil if self.empty? + self.delete_at(rand(self.length)) + end end # Extensions to the Range class -- cgit v1.2.3