On Mon, Jan 16, 2012 at 3:17 PM, Emil Enem=E6rke <eme / medical-insight.com> =
wrote:
> Hi,
>
> Im trying to make an array a global array, but I cannot make it work.

"server" references a Hash.

> Here is what I have:
> ------------
> hostname=3Dserver1
> server =3D Hash.new { |hash, key| hash[key] =3D [] }
> service_name=3D"service name"
> service=3Dservice1
>
> if server.key?(hostname)

Will likely return false because the Hash is empty initially.

> =A0 =A0 =A0server[hostname]=3DHash.new { |hash, key| hash[key] =3D [] }
> =A0 =A0 =A0server[hostname]["service_name"]=3DArray.new
> =A0 =A0 =A0server[hostname]["service_name"]=3D"service#{service_counter}"
> =A0 =A0 =A0server[hostname]["service_name"]=3D[x,x,x]

The three lines above all overwrite the same entry.  That's almost
certainly not what you want.

> end
> -----------------
>
> I have tried with
> $server[hostname]["service_name"]=3D[x,x,x]
> $server[hostname]["service_name"]=3DArray.new
>
> but that does not work... Any help is appreciated.

I am not 100% sure what you intend but I think you might just want

server =3D Hash.new { |hash, key| hash[key] =3D {} }
server[hostname]["service_name"] =3D ["service#{service_counter}", [x,x,x]]

Kind regards

robert

--=20
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/