I am trying to find if there is mango/cc:
in my data
and if its there update its value to new_version
, if its not there add mango/cc:#{new_version}
My data
{"product"=>"fruit", "id"=>"alpha", "details"=>{"SS"=>["mango/aa:50", "mango/cc:287_457_51.0.0"]}}
Code:
new_version = "287_457_53.0.0"
var1 = data['details']['SS'].select{|x| x.start_with?('mango/cc:')}
if var1.empty?
data['details'] << "mango/cc:#{new_version}"
else
data['details'].delete(var1)
data['details'] << "mango/cc:#{new_version}"
puts data
Current Output:
`[]': no implicit conversion of String into Integer (TypeError)
Expected Output:
{"product"=>"fruit", "id"=>"alpha", "details"=>{"SS"=>["mango/aa:50", "mango/cc:287_457_53.0.0"]}}
Aucun commentaire:
Enregistrer un commentaire