From: "ara.t.howard" Date: 2007-10-27T02:23:26+09:00 Subject: Re: Skip the first invocation e.g. skip_first { foo } On Oct 26, 2007, at 7:15 AM, Brian Adkins wrote: >> >> cfp:~ > cat a.rb >> block = lambda{ block = lambda{ puts 'foo' } } >> 3.times{ block.call } > > Clever :) I've used a similar technique in JavaScript, but I don't > like defining the code outside of the loop, and it's also not as clear > as other solutions IMO. > > it's just a building block... to generalize your idea, now that you sketched it out more fully, i'd probably do cfp:~ > cat a.rb class Proc def skip(n, i = 0) lambda{|*a| call *a if (i += 1) > n } end end class Object def skip(n, &block) block.skip n end end 3.times &skip(1){ puts 'foo' } %w[ a b c ].each_with_index &skip(2){|element, index| p element, index} cfp:~ > ruby a.rb foo foo "c" 2 a @ http://codeforpeople.com/ -- share your knowledge. it's a way to achieve immortality. h.h. the 14th dalai lama