Hello -- On Thu, 19 Apr 2001, John Kaurin wrote: > I made some modifications to the code supplied by > Pete Kernan [ruby-talk 13597]. Hope this is of > interest. > > # Re: [ruby-talk 13589, 13593, 13594, 13597] > > # Determines if an array's elements are in sequential > # order or the order specified by an optional block. > > class Array > def seq? > return true if length <= 1 > if block_given? > (0..length-2).to_a.each do |i| > return false unless yield (self[i]) == self[i + 1] > end > true > else > (0..length-2).to_a.each do |i| > return false unless self[i].next == self[i + 1] > end > true > end > end > end You might want to refactor a little so that you don't have (almost) the same code twice. Also you don't need to test for length, because if length <= 1 the do block won't be executed at all. And you don't have to call #to_a on the range. (Isn't that a song? :-) class Array def seq? (0..length-2).each do |i| return false unless self[i + 1] == if block_given? yield self[i] else self[i].next end end true end end David -- David Alan Black home: dblack / candle.superlink.net work: blackdav / shu.edu Web: http://pirate.shu.edu/~blackdav