我有这个散列:红宝石VS符号中的字符串哈希
{
"title"=>"Navy to place breath-test machines on all its ships",
"url"=>"http://feeds.washingtonpost.com/click.phdo?i=a67626ca64a9f1766b8ba425b9482d49"
}
事实证明,
hash[:url] == nil
和
hash['url'] == "http://feeds.washingtonpost.com/click.phdo?i=a67626ca64a9f1766b8ba425b9482d49"
为什么?它是否不适用于?
这是Rails。哦,与Ruby同时学习Rails的生活。 – 2012-03-15 01:45:52
抱歉是迂腐,但HashWithInDifferentAccess其实只是检查密钥是否是一个符号,并强制进入一个字符串,如果是这样的话,而不是其他方式https://github.com/rails/rails/blob/3d6eafe32ed498784dba2b9782bbf7df47ebeb6b/activesupport /lib/active_support/hash_with_indifferent_access.rb#L152 – 2012-03-15 01:48:27
好的。更新。 – 2012-03-15 19:50:16