Q:

Ruby hash array returning key instead of value?

[1] pry(main)> o.items
=> [{"78"=>"{\"size\"=>\"96\", \"side\"=>[]}"}]

[2] pry(main)> o.items[0]
=> {"78"=>"{\"size\"=>\"96\", \"side\"=>[]}"}

[3] pry(main)> o.items[0]['78']
=> "{\"size\"=>\"96\", \"side\"=>[]}"

[4] pry(main)> o.items[0]['78']["side"]
=> "side"

Isn't line 4 supposed to return an empty array? How come its returning "side"?
EDIT
I found this happens after saving the array of hashes (it is an array of hstore on postgresql). 
E.g
This returns a hash as intended.
o.items << {78 => {"size" => 1, "side" => []}}
o.items
=> [{"78"=> {"size"=>"1", "side"=>[]}}]  

But after saving it 
o.save
o.items
=> [{"78"=>"{\"size\"=>\"96\", \"side\"=>[]}"}]

I ended up doing eval(o.items[0]['78']) to convert the string back into a hash before making any changes to the hash and making updates. This seems very unnecessary, are there better options?

A:

As the commenters pointed out, the problem lies in the data type. You thought that the value was a hash when it fact it was a string. The escaped double quotes are the clues here.
"{\"size\"=>\"96\", \"side\"=>[]}"

vs
{"size"=>"96", "side"=>[]}

See the difference?
When you have a string and access it using the String#[] method, it returns that string when it is present. The documentation says:
If a match_str is given, that string is returned if it occurs in the string.

Check this link for more details:
http://ruby-doc.org/core-2.3.0/String.html#method-i-5B-5D

