[英]delete attributes nested within an array of objects Ruby on rails
我需要大量删除attr7_nested
中的属性nested1
,我不需要将这些数据保存在银行中,只需将其存储在变量中以发送到日志文件。
示例文件如下:
[{
"attr1": 120,
"attr2": 24,
"attr3": 11400,
"attr4": "Caixa",
"attr5": 2000000,
"attr6": 1744000,
"attr7_nested": {
"nested1": 1,
"nested2": "Essential",
"nested3": "med",
"nested4": "Med"
}
},
{
"attr1": 120,
"attr2": 24,
"attr3": 11400,
"attr4": "Caixa",
"attr5": 2000000,
"attr6": 1744000,
"attr7_nested": {
"nested1": 1,
"nested2": "Ess",
"nested3": "med",
"nested4": "Med"
}
}]
当array
是包含问题中的嵌套散列的数组时,以下内容将从所有嵌套的attr7_nested
散列中删除nested1
键:
array.each { |hash| hash[:attr7_nested].delete(:nested1) }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.