From: Brian Candler Date: 2009-01-16T05:58:20+09:00 Subject: Re: undefined method `[]' for nil:NilClass - how to prevent? Axel Etzold wrote: > A conceptually cleaner way yet would be to assign a default value to the > array variable, > > array=Array.new(['nothing in here']) Note: unlike Hashes, Arrays don't have default values. When creating an Array, you can fill it with a specific number of values: array = Array.new(5,99) # [99,99,99,99,99] This form inserts n identical references to the *same* object. If you want distinct objects, then you have to use the block form: array = Array.new(5) { ['nothing in here'] } Regards, Brian. -- Posted via http://www.ruby-forum.com/.