Keys Of Hash


  1. Practice manipulating hashes
  2. Practice using the splat operator
  3. Understand what monkey patching is


Fork and clone this lab. Run learn to see what the tests require of you. In this lab you'll be modifying Ruby's Hash class. This is called monkey patching.

What is Monkey Patching

Monkey patching is the practice of re-opening and modifying pre-existing classes. So, Ruby already has a Hash class, the instances of which you've been working with in the past two units. If we create a file that reads:

class Hash

  #some stuff


Ruby will understand that the Hash class already exists and that you are modifying/adding to it.


Monkey patching is generally avoided. You don't want to mess with the implementation of the objects and methods native to Ruby. It could get messy, fast. What if you monkey patch the Hash class and accidentally overwrite or interfere with some functionality that you need to utilize? What if you monkey patch the hash class and then your bff/co-worker/boss/someone you have never even met before in our wonderful open-source community tried to build on your code and gets confused and thwarted by your monkey patches?

Back to the instructions...

You'll be coding your solution in lib/keys_of_hash.rb. You'll fill out the content of the keys_of_hash method which is an instance method that we are adding to the Hash class. This means that any instance of the Hash class, i.e. any hash, can now have .keys_of_hash called on it.

This method should take an undefined number of arguments, using the splat operator, and return an array with every key from the hash whose value matches the value(s) given as an argument.


View Keys Of Hash on and start learning to code for free.

Unlock your future in tech
Learn to code.

Learn about Flatiron School's Mission

With a new take on education that falls somewhere between self-taught prodigy and four-year computer science degree, the Flatiron School promises to turn students with little programming experience into developers.

In the six months since the Manhattan coding school was acquired by WeWork, it has spawned locations in Washington, D.C., Brooklyn, and London. Now, WeWork is opening a fourth Flatiron School location, this time in Houston.

Adam Enbar, Flatiron School's cofounder, believes now is the time to grow. "How the world is changing has impacted working and learning in very similar ways. We think education fundamentally is about one thing: enabling people to pursue a better life."

Learn. Love. Code.
Students come to Flatiron School to change their lives. Join our driven community of career-changers and master the skills you need to become a software engineer or a data scientist.
Find Us