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 }
精彩评论