ruby - Best way to access the values of a nested hash -
here hash:
{"funds"=> {"0"=> {"sector"=>"6555", "fund_id"=>"4308", "percent"=>"20.0", "fund_distribution_id"=>"315304" } } }
how values sector
, fund_id
etc?
if following undefined method '[]' nil:nilclass because it's looking 'sector' key of '0'
params[:funds].each_with_index |f, index| puts f[index]['sector'] end
if
x = {"funds"=> {"0"=> {"sector"=>"6555", "fund_id"=>"4308", "percent"=>"20.0", "fund_distribution_id"=>"315304" } } }
, can value of sector , fund_id by
x["funds"]["0"]["sector"] x["funds"]["0"]["fund_id"]
Comments
Post a Comment