That is a much more elegant solution than mine, thanks.
But this does not solve my problem, I have the hash created within a
loop but are not able to access to array from outside that loop, due the
hash not being global. So how can I make the
server[hostname][“service_name”] = [“service#{service_counter}”,
[x,x,x]]
a global variable?
That was the intention, if the hash is empty create it.
But this won’t work as intended: you create the Hash stored in
“server” with a block which creates Arrays internally. For that
mechanism to work you just access server[some_key] and work with what
you get. If you ask whether the key exists you always get false:
And if you ask for the key then you need to take action if it is NOT
there but your code assigns only to server[hostname] if server.key?
hostname returned true. You need to at leas negate the condition.
That is a much more elegant solution than mine, thanks.
But this does not solve my problem, I have the hash created within a loop but
are not able to access to array from outside that loop, due the hash not being
global. So how can I make the
server[hostname][“service_name”] = [“service#{service_counter}”, [x,x,x]]
a global variable?
Prepend $.
Regards
robert
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.