Class | Irc::QueueRing |
In: |
lib/rbot/ircsocket.rb
|
Parent: | Object |
A QueueRing is implemented as an array with elements in the form [chan, [message1, message2, …] Note that the channel chan has no actual bearing with the channels to which messages will be sent
# File lib/rbot/ircsocket.rb, line 92 92: def initialize 93: @storage = Array.new 94: @last_idx = -1 95: end
# File lib/rbot/ircsocket.rb, line 102 102: def length 103: len = 0 104: @storage.each {|c| 105: len += c[1].size 106: } 107: return len 108: end
# File lib/rbot/ircsocket.rb, line 126 126: def next 127: if empty? 128: warning "trying to access empty ring" 129: return nil 130: end 131: save_idx = @last_idx 132: @last_idx = (@last_idx + 1) % @storage.size 133: mess = @storage[@last_idx][1].first 134: @last_idx = save_idx 135: return mess 136: end
# File lib/rbot/ircsocket.rb, line 115 115: def push(mess, chan) 116: cmess = @storage.assoc(chan) 117: if cmess 118: idx = @storage.index(cmess) 119: cmess[1] << mess 120: @storage[idx] = cmess 121: else 122: @storage << [chan, [mess]] 123: end 124: end
# File lib/rbot/ircsocket.rb, line 138 138: def shift 139: if empty? 140: warning "trying to access empty ring" 141: return nil 142: end 143: @last_idx = (@last_idx + 1) % @storage.size 144: mess = @storage[@last_idx][1].shift 145: @storage.delete(@storage[@last_idx]) if @storage[@last_idx][1] == [] 146: return mess 147: end