From: Josselin Date: 2006-10-20T20:40:07+09:00 Subject: Re: filling an array excepted first and last position... On 2006-10-20 10:32:18 +0200, Robert Klemme said: > On 20.10.2006 09:59, Josselin wrote: >> ldom = 30 # variable (last day of a month...) >> >> # array init to 0 >> @obk = [] >> 1.step(ldom, 1) do |i| >> @obk[i] = 0 >> end > > @obk = Array.new(ldom, 0) better , avoiding @obk[0] = nil ... > >> I am filling an array as follows (part of a larger filling scheme) : >> ---- >> #fiiling the array upon another array content >> # but I'd like to AVOID filling the first and last position in this loop.... >> obdays.each do |bd| >> @obk[bd] = 1 >> end >> ------ >> # ajusting first and last position (in the larger scheme) >> @obk[obdays.first] += -1 >> @obk[obdays.last] += -2 > > I am not exactly sure what problem you have with this approach. Here > is a different one > > obdays.each_with_index do |bd, idx| > case idx > when 0 > # ignore, @obk[bd] is 0 already > when obdays.length - 1 > # set to 1 + (-2) = -1 > @obk[bd] = -1 > else > @obk[bd] = 1 > end > end > > Does that help? > > robert yes and no, I cannot test @obk[bd] == 0 as it may change.... as indicated in one of my response post