Class Array
In: lib/rbot/core/utils/extends.rb
Parent: Object
User HTTPResponse BasicUserMessage Bot\n[lib/rbot/core/remote.rb\nlib/rbot/core/utils/extends.rb\nlib/rbot/core/utils/filters.rb\nlib/rbot/core/utils/wordlist.rb] HttpUtil Array Module Numeric Range String\n[lib/rbot/botuser.rb\nlib/rbot/core/utils/extends.rb\nlib/rbot/irc.rb\nlib/rbot/ircsocket.rb\nlib/rbot/load-gettext.rb] Regexp\n[lib/rbot/core/utils/extends.rb\nlib/rbot/irc.rb\nlib/rbot/messagemapper.rb] lib/rbot/core/userdata.rb lib/rbot/core/utils/httputil.rb lib/rbot/core/utils/extends.rb lib/rbot/core/remote.rb lib/rbot/core/utils/httputil.rb ParseTime Utils (null) dot/f_13.png

Extensions to the Array class

Methods

Public Instance methods

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 100
100:   def delete_one(val=nil)
101:     return nil if self.empty?
102:     if val.nil?
103:       index = rand(self.length)
104:     else
105:       index = self.index(val)
106:       return nil unless index
107:     end
108:     self.delete_at(index)
109:   end

This method returns a random element from the array, or nil if the array is empty

[Source]

    # File lib/rbot/core/utils/extends.rb, line 90
90:   def pick_one
91:     return nil if self.empty?
92:     self[rand(self.length)]
93:   end

[Source]

     # File lib/rbot/core/utils/extends.rb, line 116
116:     def shuffle
117:       sort_by { rand }
118:     end

[Source]

     # File lib/rbot/core/utils/extends.rb, line 123
123:     def shuffle!
124:       replace shuffle
125:     end

[Validate]