我有這個散列:紅寶石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