Rebuild the include? Method in Ruby to Check for Array Values


In this coding exercise we’ll walk through how to rebuild Ruby’s include? method to see if a value exists inside of an array.


Rebuild Ruby’s include? method and add a method to the Array class that checks to see if a value exists within an array.

Exercise File

Code File

Exercise Description

In order to properly pass this coding exercise you’ll need to open up Ruby’s Array class and add a method called does_it_have? that takes in an argument and then have the method return true or false depending on whether the element passed in as the method argument is included in the array or not.

Sample Process

arr = [2, 5, 100, 4]
arr.does_it_have? 5 # true
arr.does_it_have? 20 # false

Real World Usage

It’s important to understand how Ruby’s Array class operates and this exercise you’ll learn how to properly loop through a collection and return different values based on the method’s input.


Can be found on the solutions branch on github.


Please enter your comment!
Please enter your name here