Class: MsgBuffer
- Inherits:
-
Object
- Object
- MsgBuffer
- Defined in:
- lib/monitor/server/msg_buffer.rb
Instance Method Summary collapse
- #empty? ⇒ Boolean
- #full? ⇒ Boolean
- #get ⇒ Object
- #has_more? ⇒ Boolean
-
#initialize(size) ⇒ MsgBuffer
constructor
A new instance of MsgBuffer.
-
#nitems_local(arr) ⇒ Object
nitems method does not exist anymore in ruby 1.9.3.
- #put(msg) ⇒ Object
Constructor Details
#initialize(size) ⇒ MsgBuffer
Returns a new instance of MsgBuffer.
14 15 16 17 |
# File 'lib/monitor/server/msg_buffer.rb', line 14 def initialize(size) @buff = Array.new() @size=size end |
Instance Method Details
#empty? ⇒ Boolean
36 37 38 |
# File 'lib/monitor/server/msg_buffer.rb', line 36 def empty? return nitems_local(@buff) == 0 end |
#full? ⇒ Boolean
32 33 34 |
# File 'lib/monitor/server/msg_buffer.rb', line 32 def full? nitems_local(@buff) >= @size end |
#get ⇒ Object
24 25 26 |
# File 'lib/monitor/server/msg_buffer.rb', line 24 def get() return @buff.pop end |
#has_more? ⇒ Boolean
28 29 30 |
# File 'lib/monitor/server/msg_buffer.rb', line 28 def has_more? nitems_local(@buff) != 0 end |
#nitems_local(arr) ⇒ Object
nitems method does not exist anymore in ruby 1.9.3
4 5 6 7 8 9 10 11 12 |
# File 'lib/monitor/server/msg_buffer.rb', line 4 def nitems_local(arr) cpt = 0 arr.each {|val| if val cpt+=1 end } return cpt end |
#put(msg) ⇒ Object
19 20 21 22 |
# File 'lib/monitor/server/msg_buffer.rb', line 19 def put(msg) @buff.unshift(msg) #puts "message put nitems=" + nitems_local(@buff).to_s end |