Global variables ?
Are you sure you need global variables?
Right now, the keys in your hash aren't string, symbol or integers, but the object referenced by the variables $username
and $password
. Those variables are global, and are accessible from everywhere in your code. This doesn't seem to be a good idea for a variable called password
.
If those variables aren't initialized, they both are nil
, so your login_form
is actually :
{nil=>{:web_element_type=>:id, :web_element=>"pass"}}
The values for $username
have been overwritten by $password
.
If you're sure that login_form
should be a global variable :
$login_form = {
username: {web_element_type: :id, web_element: 'uname'},
password: {web_element_type: :id, web_element: 'pass'}
}
p $login_form[:password].values_at(:web_element_type, :web_element)
#=> [:id, "pass"]
type, element = $login_form[:password].values_at(:web_element_type, :web_element)
p type
#=> :id
p element
#=> "pass"
If not, you could use @login_form
or just login_form
.
If you're still confused, you could look at this.