Skip to content

Instantly share code, notes, and snippets.

@pcg79
Created September 26, 2014 18:37
Show Gist options
  • Save pcg79/9bb8cf5d554645fcec33 to your computer and use it in GitHub Desktop.
Save pcg79/9bb8cf5d554645fcec33 to your computer and use it in GitHub Desktop.
Yaml file for music
genres:
- name: Classic Rock
artists:
- name: Led Zeppelin
albums:
- name: I
tracks:
- name: Babe, I'm Gonna Leave You
- name: Black Mountain Side
- name: Communication Breakdown
- name: Dazed And Confused
- name: Good Times, Bad Times
- name: How Many More Times
- name: I Can't Quit You Baby
- name: You Shook Me
- name: Your Time Is Gonna Come
- name: II
tracks:
- name: Bring It On Home
- name: Heartbreaker
- name: The Lemon Song
- name: Living Loving Maid
- name: Moby Dick
- name: Ramble On
- name: Thank You
- name: What Is And What Should Never Be
- name: Whole Lotta Love
- name: Jazz
artists:
- name: John Coltrane
albums:
- name: My Favorite Things
tracks:
- name: My Favorite Things
- name: Every Time We Say Goodbye
- name: Summertime
- name: But Not For Me
@pcg79
Copy link
Author

pcg79 commented Sep 26, 2014

Given the a Yaml file of the format found in music.yaml parse the file so that we can access it in Ruby.

Your parsing code should return an object that allows you to access attributes using the [] operator:

data["genres"].last["artists"].first["albums"].first["tracks"].last["name"] => "But Not For Me"

The returned object should also allow you to access attributes using method calls:

data.genres.last.artists.first.albums.first.tracks.last.name => "But Not For Me"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment