From: Sean O'Halpin Date: 2007-10-26T09:23:19+09:00 Subject: Re: Skip the first invocation e.g. skip_first { foo } ------=_Part_2829_829289.1193358200322 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline On 10/26/07, Brian Adkins wrote: > > What I'm trying to accomplish is a convenient way to execute a block > of code on every iteration except the first (or only on the first > iteration). > I haven't figured out a way to avoid initializing outside the loop, but is this the kind of functionality you're after? def skipn(n) x = -1 proc {|block| if (x += 1) == n block.call true else false end } end skip = skipn(1) # or 0 or 2 or ... ('a'..'d').each do |i| next if skip[ proc { puts "Hi" } ] puts i end skip = skipn(1) ('a'..'d').each do |i| break if skip[ proc { puts "Hi" } ] puts i end __END__ a Hi c d a Hi Regards, Sean ------=_Part_2829_829289.1193358200322--