From: Matthew Moss Date: 2006-07-07T02:18:12+09:00 Subject: Re: A newbie would like some code criticism, please... > There's also a pattern that often comes up for me and I would like some > help with it... > > first = true > list.each do |item| > if first > # do something special for the first case > > first = false > else > # do something else for every other item > end > end > > Is there a better way to do this? Perhaps some way to simply iterate > over every element other than the first one? Something that avoid a check > every iteration? I usually add a couple of methods to Array to facilitate such things, named after funcs from my ol' ML days: class Array def head first end def tail self[1..-1] end end list.head.do_something_special list.tail.each do |item| item.do_something_else end