range checking or seek method

M

Martin Durai

Hi friends i was in a process of creating a ring buffer and i have done
read, write methods for it. i need seek methods which does range
checking. A seek method should take mumber as a argument and return
nothing. seek changes the read position. I have attached my coding with
it please help me with code to do seek method. if needs change read aned
write method also.

class RingBuffer

# Instanciate a ring buffer of the given size.
# The buffer will contain at most +size+ elements

def initialize(size)

@max = size

@buffer = Array.new

end


def read(number_of_bytes)
#------------------------------------

[email protected]

puts buffer_size

if number_of_bytes < buffer_size

@newBuffer = Array.new

@newBuffer = @buffer[0..number_of_bytes]

puts "Inside no of bytes "

@newBuffer.each() { |block| puts block.to_s}

else

@newBuffer = Array.new

@newBuffer = @buffer[0..buffer_size]

puts "Inside buffer size "

@newBuffer.each() { |block| puts block.to_s}

end

end

def write(string_value)
#-----------------------------

[email protected]

puts buffer_size

if buffer_size > @max

@buffer.shift

else

@buffer << string_value

end

[email protected]

puts buffer_size

end

def seek

end




end
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top