Created
October 1, 2013 05:33
-
-
Save rayning0/6774254 to your computer and use it in GitHub Desktop.
Create Some Hashes. Did a 4-level movie hash. Tried to create complicated hash with code. Didn't fully work.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| movies = [ | |
| 'Thriller - Denis Villeneuve - Hugh Jackman - Prisoners', | |
| 'Thriller - James Wan - Patrick Wilson - Insidious', | |
| 'Thriller - James Wan - Patrick Wilson - The Conjuring', | |
| 'Thriller - Neill Blomkamp - Matt Damon - Elysium', | |
| 'Action - Ron Howard - Chris Hemsworth - Rush', | |
| 'Action - Joss Whedon - Robert Downey Jr - The Avengers', | |
| 'Action - Joss Whedon - Scarlett Johansson - The Avengers: Age of Ultron', | |
| 'Comedy - Ron Howard - Tom Hanks - Splash' | |
| ] | |
| library = {} | |
| =begin | |
| { | |
| 'Thriller' => { | |
| 'James Wan' => {'Patrick Wilson' => ['Insidious', 'The Conjuring']}, | |
| 'Denis Villeneuve' => {'Hugh Jackman' => ['Prisoners']} | |
| } | |
| 'Action' => { | |
| 'Ron Howard' => {'Chris Hemsworth' => ['Rush']}, | |
| 'Joss Whedon' => { | |
| 'Robert Downey Jr' => ['The Avengers'], | |
| 'Scarlett Johansson' => ['The Avengers: Age of Ultron']} | |
| } | |
| } | |
| =end | |
| # This does not fully work. Need to fix it: | |
| movies.each do |movie| | |
| #binding.pry | |
| genre, director, actor, film = movie.split(' - ') | |
| if library[genre] && library[genre][director] & library[genre][director][actor] | |
| library[genre][director][actor] << film | |
| elsif library[genre] && library[genre][director] | |
| library[genre][director][actor] = [film] | |
| elsif library[genre] | |
| library[genre][director] = {actor => [film]} | |
| else | |
| library[genre] = {director => {actor => [film]}} | |
| end | |
| p library | |
| end | |
| puts library |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment