Beginner Question = How do I access a Symbol in an Array

Sorry for such an elementary question, but having no luck finding it on any search engines. . .

I have created an array of symbols. . .
family_data = [:id, :name, :brush_color, :primary_insured_id, :contract_effective_date]
I have successfully loaded the array from a file. . .
.with_index do |line, i|
fields = line.split(",")
family_data.push(id: fields[0], name: fields[1].downcase.capitalize, brush_color: fields[2].downcase, primary_insured_id: fields[3], contract_effective_date: fields[4].chomp)

I can see the entire array. . .
puts(“family_data: " + family_data[-1].to_s)
family_data: {:id=>“6”, :name=>“Ben”, :brush_color=>“green”, :primary_insured_id=>“3”, :contract_effective_date=>”"}

Can not figure out how to access onesymbol an array entry?. . .
puts("family_data[-1].:name: " + family_data[-1].:name)

I have tried many variations. Any suggestions would be greatly appreciated.



Thanks for reading this. . .I found the syntax (by trial and error, still have not found anything in the search engines). . .This works for me. . .

puts("family_data[-1].:name: " + family_data[-1][:name])


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs