有没有办法做这样的事情:
numbers = {
"one" => "two",
"three" => numbers["one"] }
我知道我可以制作哈希并将所有内容设置为numbers["one"]
,但丑陋......
答案 0 :(得分:1)
不,因为尚未定义numbers
,但您可以将项目多次分配为变量:
# seems odd, but ok...
def_num = "two"
numbers = { 'one' => def_num, 'two' => def_num }