根据键在第一个数组元素中追加字符串

时间:2015-11-19 17:15:21

标签: ruby

我有这个数组:

address_types = ["main", "invoice", "work"]

我想将这个数组转换为:

[
  ["#{t('activerecord.attributes.address.address_type.main')}", "main"], 
  ["#{t('activerecord.attributes.address.address_type.invoice')}", "invoice"],
  ["#{t('activerecord.attributes.address.address_type.work')}", "work"]
]

我怎样才能做到这一点?

1 个答案:

答案 0 :(得分:1)

address_types.map do |entry|
  [t("activerecord.attributes.address.address_type.#{entry}"), entry]
end