On Jul 20, 2013, at 2:51 PM, Serguei Cambour <lists / ruby-forum.com> = wrote: > I tried to use ActiveSupport 'underscore' method to convert some > non-conventional to RoR data to be able to update later some = attributes > as follows: >=20 > TECHS =3D {"platform"=3D>[ > {"AssignedName"=3D>"P1", "ExportPrice"=3D>"USD", = "Id"=3D>"1", > "Delivery"=3D>"Y", > "RegisteredMembers"=3D>[ > {"Name"=3D>"Admin", "Id"=3D>"3", > "AvailablePosts"=3D>[ > {"Seat"=3D>"2", "Colour"=3D>18, }, > {"Seat"=3D>"3", "Colour"=3D>19, }, > {"Seat"=3D>"4", "Colour"=3D>181, }, > {"Seat"=3D>"5", "Colour"=3D>183, } > ] > } > ] > } > ] > } >=20 > TECHS.each_value do |value| > arr =3D value.map {|k,v| = [ActiveSupport::Inflector.underscore(k.to_s), > v]} > puts "ARR: #{arr.inspect}" > end >=20 > The result is strange even if the values look underscored: >=20 > ARR: [["{\"assigned_name\"=3D>\"p1\", \"export_price\"=3D>\"usd\", > \"id\"=3D>\"1\", \"delivery\"=3D>\"y\", > \"registered_members\"=3D>[{\"name\"=3D>\"admin\", \"id\"=3D>\"3\", > \"available_posts\"=3D>[{\"seat\"=3D>\"2\", \"colour\"=3D>18}, > {\"seat\"=3D>\"3\", \"colour\"=3D>19}, {\"seat\"=3D>\"4\", = \"colour\"=3D>181}, > {\"seat\"=3D>\"5\", \"colour\"=3D>183}]}]}", nil]] >=20 > Why are there some extra quotes and nil in the very end ? Thkx >=20 > --=20 > Posted via http://www.ruby-forum.com/. >=20 Not 100% sure what you're seeing as extra quotes, but the nil is what = you get from declaring two passed in values from the map method -- it = only passes in the current value of the array that your original = TECH['platform'] is pointing at, so k is current value, v is always nil. 2.0.0-p247 :008 > [1, 2, 3, 4].map{|k,v| [k,v]} =3D> [[1, nil], [2, nil], [3, nil], [4, nil]]=20 Even if your array elements are hashes, there's still only one value = passed in from map: 2.0.0-p247 :009 > [{a: 1, b: 2, c: 3}, {aa: 11, bb: 22, cc: = 33}].map{|k,v| [k,v]} =3D> [[{:a=3D>1, :b=3D>2, :c=3D>3}, nil], [{:aa=3D>11, :bb=3D>22, = :cc=3D>33}, nil]]=20