Мне нужно удалить все ключи созданные_at и updated_at в массиве хэшей. Мой ха sh выглядит так:
assessment_with_desc = {
"id": 1,
"name": "First assessment",
"created_at": "2020-03-14T20:13:27.006Z",
"updated_at": "2020-03-14T20:13:27.006Z",
"description_with_child_models": [
{
"id": 3,
"title": "First category",
"created_at": "2020-02-20T15:32:46.379Z",
"updated_at": "2020-03-14T20:16:11.530Z",
"accessment_id": 1,
"sub_categories": [
{
"id": 1,
"title": "First sub_category",
"category_id": 3,
"created_at": "2020-02-20T15:40:49.793Z",
"updated_at": "2020-02-20T15:40:49.793Z",
"stages": [
{
"id": 5,
"title": "First stage",
"sub_category_id": 1,
"created_at": "2020-02-20T15:44:10.603Z",
"updated_at": "2020-02-20T15:44:10.603Z"
}
]
}
]
}
]
}
Я сделал это, но это работает только в этом случае assessment_with_desc.delete('created_at')
и assessment_with_desc.delete('updated_at')
:
assessment_with_desc.delete('created_at')
assessment_with_desc.delete('updated_at')
assessment_with_desc['description_with_child_models'].delete('created_at')
assessment_with_desc['description_with_child_models'].delete('updated_at')
assessment_with_desc['description_with_child_models'][0]['sub_categories'].delete('created_at')
assessment_with_desc['description_with_child_models'][0]['sub_categories'].delete('updated_at')
assessment_with_desc['description_with_child_models'][0]['sub_categories'][0]['stages'].delete('created_at')
assessment_with_desc['description_with_child_models'][0]['sub_categories'][0]['stages'].delete('updated_at')