I have a scenario that when I try to access a hash key using a symbol it doesn't work, but when I access it with a string it works fine. It is my understanding that symbols are recommended over strings, so I am trying to clean my script. I am using hash symbols elsewhere in my script, it is just this specific scenario that does not work.
Here is the snippet:
account_params ={}
File.open('file', 'r') do |f|
f.each_line do |line|
hkey, hvalue = line.chomp.split("=")
account_params[hkey] = hvalue
end
end
account_scope = account_params["scope"]
This works, however if I use a symbol it doesn't, as shown below:
account_scope = account_params[:scope]
When I use a symbol I get:
can't convert nil into String (TypeError)
I am not sure if it matters, but the contents of this specific hash value looks something like this:
12345/ABCD123/12345