I have a yaml file tasks.yml that declares a hash thus:
"Place1 8a-5p":
type: "W"
abbr: "w"
"SpotX 7:00a-4:00p":
type: "W"
abbr: "w"
"AnotherSpot7-4":
type: "N"
abbr: "-"
pretty print of Hash looks like this:
{"Place1 8a-5p"=>{"type"=>"W", "abbr"=>"w"},
"SpotX 7:00a-4:00p"=>{"type"=>"W", "abbr"=>"w"},
"AnotherSpot7-4"=>{"type"=>"N", "abbr"=>"-"}}
When I try to reference a key like this:
tasks = YAML.load(File.read("tasks.yml"))
puts tasks.first["type"]
I get this error:
`[]': no implicit conversion of String into Integer (TypeError)
I see the same error if I use:
puts tasks.first[:type]
How do I reference the type and abbr keys for this hash?
I was trying to do this:
Which now works.
https://stackoverflow.com/users/386540/ritesh-choudhary clued me in to using 'values' directly
https://stackoverflow.com/users/3449508/daniel-sindrestean clued me in to the fact that each task contains an array of key/value pairs
More than one correct answer. Thank you all.