我有这样的数组数据:
[#<PriceList id: 463134, distributor_id: 6, brand: "Mann-filter", article_nr: "W712/22", price: 5405.0, quantity: "50", waittime: 1, description: "Фильтр масл OPEL 1.2-3.0L (OC90)", created_at: "2013-01-30 16:35:34", updated_at: "2013-01-30 16:35:34", art_group: "Фильтр масл OPEL 1.2-3.0L (OC90)", oem_number: nil>, #<PriceList id: 517164, distributor_id: 6, brand: "Mann-filter", article_nr: "W712/22", price: 5442.0, quantity: "500", waittime: 3, description: "Фильтр масляный OPEL/GM/DAEWOO", created_at: "2013-01-30 16:42:26", updated_at: "2013-01-30 16:42:26", art_group: "Фильтр масляный OPEL/GM/DAEWOO", oem_number: nil>, #<PriceList id: 463135, distributor_id: 6, brand: "Mann-filter", article_nr: "W712/22(10)", price: 5101.0, quantity: "20", waittime: 1, description: "Фильтр масл.без упак.OPEL/GM (OC90Of)", created_at: "2013-01-30 16:35:34", updated_at: "2013-01-30 16:35:34", art_group: "Фильтр масл.без упак.OPEL/GM (OC90Of)", oem_number: nil>, ... etc我怎样才能改变价格类型?
我试着
@non_original2 = @non_original2.map { |e| e[:price].to_i }但结果我只看到了价格..。如何更改数组,使所有散列中的价格字段变为整数值?
发布于 2013-07-25 11:57:54
关于
@non_original2.each { |e| e[:price] = e[:price].to_i }这将更改列表中的每个PriceList项(而不复制列表)。
使用您的方法会产生一个价格值列表,因为map收集块的结果。e[:price].to_i的结果是整数(您看到的价格)。
https://stackoverflow.com/questions/17857273
复制相似问题