From: Martin Durai Date: 2007-11-21T12:13:59+09:00 Subject: Re: read, write, seek method in a ring buffer class Iam new to this language, could u help me out to solve this problem class RingBuffer # Instanciate a ring buffer of the given size. # The buffer will contain at most +size+ elements def initialize(size) # initialize the max @max = size # initialize the buffer array @buffer = Array.new(size) # initialize the read position @read_position = read_position # initialize the write position @write_position = write_position end # # Method to clear the buffer # def clear @buffer = [] end # # method call to read the contents in a buffer # def read(read_position) # is read position is greater than the maximum if @read_position > @max # if so raise "Illeagal Read Position, the value is greater than the maximum value of buffer" # is read position is lesser than the minimm value if @read_position < -1 # if so raise " Illeagal Read Position, the value is less than minimum" end end # read the buffer value str = @buffer[read_position].to_s # return the string return str end # # method call to write contents in a buffer # def write(value) # shift the buffer @buffer.shift # append the value at the end @buffer << value end # # method call to convert buffer array # def to_a # return the buffer element return @buffer.dup end # # method call to convert to string # def to_s # initialize the str str = "" # each value in the buffer is converted to string @buffer.each { |entry| str << entry.to_s << "\n" } # return the string elements return str end # # method call to seek position # def seek end end -- Posted via http://www.ruby-forum.com/.