From: Martin Durai Date: 2007-11-22T19:41:08+09:00 Subject: Re: read, write, seek method in a ring buffer class Thank you Jes炭s for spending your precious time but unfortunately i dont want to use IO buffers. i need to use buffer as a string. so could you help me with code for my RingBuffer class displayed below class RingBuffer # Instanciate a ring buffer of the given size. # The buffer will contain at most +size+ elements def initialize(size) # initialize the maximum @max = size #Initialize the buffer @buffer = Array.new end # # method call to read contents from the buffer # def read(number_of_bytes) #------------------------------------ # initialize the buffer size buffer_size=@buffer.length # is number of bytes greater than buffer size if number_of_bytes < buffer_size # if so # initialize the new buffer array @newBuffer = Array.new # initialize new buffer @newBuffer = @buffer[0..number_of_bytes] # return all elements in buffer as string @newBuffer.each() { |block| return block.to_s} #if not else # initialize the newbuffer array @newBuffer = Array.new # initialize the now buffer @newBuffer = @buffer[0..buffer_size] # return all the elements in buffer as string @newBuffer.each() { |block| puts block.to_s} end end # # method call to write contents in the buffer # def write(string_value) #----------------------------- #initialize the buffer size buffer_size=@buffer.length # is buffer size is greater than maximum if buffer_size > @max # if so # remove the first element in the buffer @buffer.shift # if not else # write a element to the buffer @buffer << string_value end end def seek end end Thank you in advance -- Posted via http://www.ruby-forum.com/.