I have the following code. I don't understand why table['something'] is different from table[:something].
require 'json'
data = '[{"type":"local","db":"all","user":"postgres","addr":null,"method":"ident"},{"type":"local","db":"all","user":"all","addr":null,"method":"ident"},{"type":"host","db":"all","user":"all","addr":"0.0.0.0/0","method":"md5"},{"type":"host","db":"all","user":"all","addr":"::1/128","method":"md5"},{"type":"local","db":"communicator","user":"communicator","addr":" ","method":"trust"}]'
table = JSON.parse(data)
table.each do | auth |
if (auth['user'])
print( '\n\n\n' + auth[:user] )
end
end
And on line with print( '\n\n\n' + auth[:user] ), I'm receiving an error:
TypeError: no implicit conversion of nil into String
from (irb):88:in `+'
This means that accessing table via :key is different from 'key'.
Why? How do I convert table to make it work with :key instead of 'key'?