diff options
author | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2007-11-04 15:11:09 +0000 |
---|---|---|
committer | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2007-11-04 15:11:09 +0000 |
commit | 2327431c922faba63817bff7353290ba3b7cbcf4 (patch) | |
tree | f303fe9b24d3607915cd0ac24ec7f301acd36feb /lib/rbot | |
parent | 34acfe3193a3603b4c6654dd23dacfef80ce1bc2 (diff) |
extends: Arraydata/rbot/plugins/factoids.rbdelete_one to remove a random element from an array
Diffstat (limited to 'lib/rbot')
-rw-r--r-- | lib/rbot/core/utils/extends.rb | 8 |
1 files changed, 8 insertions, 0 deletions
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 |