在这里摆脱这个厚重代码的任何一个很棒的衬垫?
hash = {}
hash["permission_type"] = "some permission type"
hash["vaue"] = "some value"
permission_collection = [] << hash
答案 0 :(得分:8)
permission_collection = [ {"permission_type" => "some permission type", "vaue" => "some value"} ]
答案 1 :(得分:0)
因为你要求一个单行:
permission_collection = [Hash["permission_type","some_permission_value","value","some_value"]]
IMO,最好的选择是使用Utsav的答案,但是要将哈希值分散到多行,以使其更具可读性。
类似的东西:
permission_collection = [
{
"permission_type" => "some_permission_value",
"value" => "some_value"
}
]
不止一行,但更具可读性。