title: How do you check for matching keys in a ruby hash?
body: <p>I'm learning coding, and one of the assignments is to return keys is return the names of people who like the same TV show.</p>
  
  <p>I have managed to get it working and to pass TDD, but I'm wondering if I've taken the 'long way around' and that maybe there is a simpler solution?</p>
  
  <p>Here is the setup and test: </p>
  
  <pre><code>class TestFriends &lt; MiniTest::Test
  
    def setup
  
      @person1 = {
        name: "Rick",
        age: 12,
        monies: 1,
        friends: ["Jay","Keith","Dave", "Val"],
        favourites: {
          tv_show: "Friends",
          things_to_eat: ["charcuterie"]
        }
      }
  
      @person2 = {
        name: "Jay",
        age: 15,
        monies: 2,
        friends: ["Keith"],
        favourites: {
          tv_show: "Friends",
          things_to_eat: ["soup","bread"]
        }
      }
  
      @person3 = {
        name: "Val",
        age: 18,
        monies: 20,
        friends: ["Rick", "Jay"],
        favourites: {
          tv_show: "Pokemon",
          things_to_eat: ["ratatouille", "stew"]
        }
      }
  
      @people = [@person1, @person2, @person3]
  
        end
  
        def test_shared_tv_shows
          expected = ["Rick", "Jay"]
  
          actual = tv_show(@people)
  
          assert_equal(expected, actual)
        end
      end
  </code></pre>
  
  <p>And here is the solution that I found:</p>
  
  <pre><code>def tv_show(people_list)
    tv_friends = {}
    for person in people_list
      if tv_friends.key?(person[:favourites][:tv_show]) == false
        tv_friends[person[:favourites][:tv_show]] = [person[:name]]
      else
        tv_friends[person[:favourites][:tv_show]] &lt;&lt; person[:name]
      end
    end
    for array in tv_friends.values()
       if array.length() &gt; 1
        return array
      end
    end
  end
  </code></pre>
  
  <p>It passes, but is there a better way of doing this?</p>