开发者

Use Ruby hash value inside of hash

开发者 https://www.devze.com 2023-04-02 02:07 出处:网络
Is th开发者_如何学Pythonere a way to do something like this: numbers = { \"one\" => \"two\", \"three\" => numbers[\"one\"] }

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

精彩评论

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