【发布时间】:2018-12-28 20:58:15
【问题描述】:
关于扁平化哈希的主题已经写了很多,但我找不到任何关于我的情况的信息。
我有一个散列数组的散列,等等......
类似:
{
:medical_address => [
{
:address_1 => nil,
:city => nil,
:state => nil,
:zip5 => nil,
:zip9 => nil
}
],
:pharmacy_address => [
{
:address_1 => nil,
:city => nil,
:state => nil,
:zip5 => nil,
:zip9 => nil
}
],
:address => [],
:member_phone => "8000000000",
:provider_phone => nil,
:phone => [
"800-000-0000",
"8000000000",
"800-000-0000",
"8000000000",
"800-624-5060",
"8006245060",
"804-673-1678",
"8046731678",
"888-258-3432",
"8882583432",
"800-000-0000",
"8000000000",
"800-000-0000",
"8000000000",
"800-000-0000",
"8000000000",
"800-624-5060",
"8006245060",
"804-673-1678",
"8046731678",
"888-258-3432",
"8882583432"
],
:website => [
"www.fopblue.org",
"www.fepblue.org",
"www.fepblue.org",
"www.fopblue.org"
]
}
我想把它展平成一个数组。
任何人有一个很好的简单递归函数可以方便地做到这一点? 我希望结果如下所示:
[:medical_address,:address_1, nil, :city, nil, :state, nil, :zip5, nil, :zip9, nil, :pharmacy_address, :address_1, nil, :city, nil, :state, nil, :zip5, nil, :zip9, nil,, :address,, :member_phone, "8000000000", :provider_phone, nil, :phone,"800-000-0000", "8000000000", "800-000-0000", "8000000000", "800-624-5060", "8006245060", "804-673-1678", "8046731678", "888-258-3432", "8882583432", "800-000-0000", "8000000000", "800-000-0000", "8000000000", "800-000-0000", "8000000000", "800-624-5060", "8006245060", "804-673-1678", "8046731678", "888-258-3432", "8882583432", :website,"www.fopblue.org", "www.fepblue.org", "www.fepblue.org", "www.fopblue.org"]
【问题讨论】:
-
你可以为上面的哈希添加预期的输出吗?
标签: ruby-on-rails arrays ruby hash flatten