-2
我需要寫腳本幫助我在保存之前清理散列哈希的幫助。哪個級別的標題是空的,需要刪除。以下是示例散列。遍歷和更新散列哈希的哈希
運行腳本
Questions= {
"0"=>
{
"title"=>"Question checkbox",
"id"=>"1",
"options_attributes"=>
{
"0"=>{"title"=>"1", "id"=>"1"},
"1"=>{"title"=>"2", "id"=>"2"}
},
"question_type_id"=>"4"
},
"1"=>
{
"title"=>"Question Radio",
"id"=>"2",
"options_attributes"=>
{
"0"=>
{
"title"=>"yes", "id"=>"3"
},
"1"=>
{
"title"=>"no", "id"=>"4"
},
"2"=>
{
"title"=>"", "id"=>""
}
},
"question_type_id"=>"3"
},
"2"=>
{
"title"=>"",
"options_attributes"=>
{
"0"=>{"title"=>"", "id"=>""},
"1"=>{"title"=>"", "id"=>""}
},
"question_type_id"=>"1"
}
}
運行腳本所需的結果
Questions= {
"0"=>
{
"title"=>"Question checkbox",
"id"=>"1",
"options_attributes"=>
{
"0"=>{"title"=>"1", "id"=>"1"},
"1"=>{"title"=>"2", "id"=>"2"}
},
"question_type_id"=>"4"
},
"1"=>
{
"title"=>"Question Radio",
"id"=>"2",
"options_attributes"=>
{
"0"=>
{
"title"=>"yes", "id"=>"3"
},
"1"=>
{
"title"=>"no", "id"=>"4"
}
},
"question_type_id"=>"3"
},
}