From: Sebastian Hungerecker Date: 2007-10-11T20:07:29+09:00 Subject: Re: Dynamically create hash Matthias Wiemann wrote: > Hi, > i would like to dynamically create hashes, so that I can create them by > looping over the names. You can do that using eval (or using instance variables), but that's evil. It would probably make more sense to use an array or hash of hashes. > Something like: > > for i in 1..10 > "hash#{i}" = Hash.new > "hash#{i}" = [:key => "val"] > end > > So the hashes created would go by the names hash1, hash2, hash3... hashes=Array.new(10) do |i| {:key => "val"} end This gives you hashes[0] to hashes[9]. HTH, Sebastian -- NP: Black Sabbath - Heaven and Hell Jabber: sepp2k@jabber.org ICQ: 205544826