Ruby 1.9.2 的新哈希语法有一个奇怪的问题。如何在 1.9.2 中将任何对象作为哈希键?
在 1.8.7 哈希中它可以工作:
a="b"
{"a" => "some",a => "another value",:a => "3rd value"}
但是在 1.9.2 > 我们不能(或者如果我错了怎么办?”)
1.9.2 哈希:
{a: "some"} => {:a=>"s"} #it convert to old hash format
但
a="a"
{a: "..."} # This doesn't work
{"a": "some value"} => syntax error, unexpected '}', expecting $end
from /home/naveed/.rvm/rubies/ruby-1.9.2-p290/bin/irb:16:in `<main>'
{1: "s"} =>
SyntaxError: (irb):11: syntax error, unexpected ':', expecting tASSOC {1: "s"}