假设我有 2 个字符串常量
KEY1 = "Hello"
KEY2 = "World"
我想使用这些常量作为键值创建一个散列。
尝试这样的事情:
stories = {
KEY1: { title: "The epic run" },
KEY2: { title: "The epic fail" }
}
似乎不起作用
stories.inspect
#=> "{:KEY1=>{:title=>\"The epic run\"}, :KEY2=>{:title=>\"The epic fail\"}}"
显然stories[KEY1]
不起作用。