ruby - Replace one matched value in a hash with another -


i have array of hashes:

arr = [   {:key1=>"one", :key2=>"two", :key3=>"three"},   {:key1=>"four", :key2=>"five", :key3=>"six"},   {:key1=>"seven", :key2=>"eight", :key3=>"nine"} ] 

and search through , replace value of :key1 "replaced" if :key = "one".

the resultant array read:

arr = [   {:key1=>"replaced", ;key2=>"two", :key3=>"three"},   {:key1=>"four", ;key2=>"five", :key3=>"six"},   {:key1=>"seven", ;key2=>"eight", :key3=>"nine"} ] 

can point me in right direction?

try use following code see if solves problem

arr.each{|item| item[:key1] = "replaced" if item[:key1]=="one" 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -