From: Matt Brooks Date: 2009-10-03T03:48:56+09:00 Subject: Re: Rolling String Buffer needed Justin Collins wrote: > If you want it to act like a queue with the last element being the head, > then use pop/unshift. > > irb(main):001:0> a = [1,2,3,4] > => [1, 2, 3, 4] > irb(main):002:0> a.pop > => 4 > irb(main):003:0> a.unshift 5 > => [5, 1, 2, 3] > irb(main):004:0> a.pop > => 3 > irb(main):005:0> a > => [5, 1, 2] > > > -Justin Awesome, I think I need the last approach. So incorporating it into the class, I have... class MyBuff def initialize max_size, filename @max_size = max_size @list = [] @file = File.open(filename, 'wb') end def add_to_front string @list.unshift string #changed to unshift while @list.length > @max_size @file.write @list.pop end end def [] i @list[i] end end Thanks to all, I think this will work great! -Matt -- Posted via http://www.ruby-forum.com/.