class Array
Extensions to the Array
class
Public Instance Methods
Source
# File lib/rbot/core/utils/extends.rb, line 100 def delete_one(val=nil) return nil if self.empty? if val.nil? index = rand(self.length) else index = self.index(val) return nil unless index end self.delete_at(index) end
This method returns a given element from the array, deleting it from the array itself. The method returns nil if the element couldn’t be found.
If nil is specified, a random element is returned and deleted.
Source
# File lib/rbot/core/utils/extends.rb, line 90 def pick_one return nil if self.empty? self[rand(self.length)] end
This method returns a random element from the array, or nil if the array is empty