diff options
-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 |