Nav*_*eed 2 ruby hash ruby-on-rails ruby-1.9.2
Ruby 1.9.2的新哈希语法存在一个奇怪的问题.如何在1.9.2中将任何Object作为密钥放入哈希?
在1.8.7哈希它工作:
a="b"
{"a" => "some",a => "another value",:a => "3rd value"}
Run Code Online (Sandbox Code Playgroud)
但是在1.9.2中>我们不能(或者如果我错了怎么办?)
1.9.2哈希:
{a: "some"} => {:a=>"s"} #it convert to old hash format
Run Code Online (Sandbox Code Playgroud)
但
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"}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1887 次 |
最近记录: |