From: Stefano Crocco Date: 2007-03-31T02:05:24+09:00 Subject: Re: newbie, hash or 2dArry Alle venerd狸 30 marzo 2007, Zac Elston ha scritto: > I'm lost or just tired from guessing. > > I need to make an hash I can call by hostname as the key and some random > amount of data after that as the values. now a hash works great for 1 > to 1 maps (h[serverX] ==> result) but I need > h[serverX][query|result|time] > > so how would I write a hash that would give me access to > > in: > h[host_to_query]["query"]] = @query > h[host_to_query]["result"]] = queryhost(host_to_query,@query) > > out: > for h.each |host| puts h[[host]["result"]] > > thanks > > zaq If I understand correctly, you can create a class with the required instances variables (or use Struct or OpenStruct) and store query and result there. For instance, using OpenStruct: require 'ostruct' h[host_to_query] =OpenStruct.new(:query=> @query, :result= queryhost(host_to_query,@query) then h.each_value{|v| puts v.result} For more information, you can look at the ri documentation for Hash, Struct and OpenStruct (ri Hash, ri Struct, ri OpenStruct). I hope this helps Stefano