开发者

Use Ruby hash value inside of hash

Is th开发者_如何学Pythonere a way to do something like this:

numbers = {
  "one" => "two",
  "three" => numbers["one"] }

I know I can just make the hash and set everything normally like numbers["one"] but ugly...


No, because numbers is not yet defined, but you can make the items assigned more than once a variable:

# seems odd, but ok...
def_num = "two"
numbers = { 'one' => def_num, 'two' => def_num }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜