Sebastian Hungerecker
10/11/2007 11:07:00 AM
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