[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?
o.items[0]['78']is a string, not a hash."foobar"["oba"]is"oba", as is"foobar"[/o.a/]. You searched for"side"in a string, and it was found.