From: Robert Klemme Date: 2006-10-20T17:35:13+09:00 Subject: Re: filling an array excepted first and last position... 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) > 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