temp=[
{
—hoge=>1,
—huga=>[ ]
},
{
—hoge=>2,
—huga=>[ ]
},
]
Is there a "hoge
refers to an object with 1
" in this array?
As an image, I would like to do the following:
temp[{:hoge==2}][:huga]<<123
↓
[
{
—hoge=>1,
—huga=>[ ]
},
{
—hoge=>2,
—huga=>[123]
},
]
You can use Enumerable#find
to:
temp.find {|h|h[:hoge]==1}[:huga]<<123
© 2024 OneMinuteCode. All rights reserved.