On 1/16/07, Drew Olson <olsonas / gmail.com> wrote: > I'd like to have my array behave like this: If I add an item to a[5], > a[0..5] will be equal to " " rather than nil. I tried to following: > > irb(main):001:0> a=[" "] > => [" "] > irb(main):002:0> a[5] = "test" > => "test" > irb(main):003:0> a.inspect > => "[\" \", nil, nil, nil, nil, \"test\"]" > > Is there any way to have those nils default to " "? Array.new should do what you want: a = Array.new(5, " ") # => [" ", " ", " ", " ", " "] Dave -- Dave Goodlad dgoodlad / gmail.com or dave / goodlad.ca http://david.goodlad.ca/