January 19 - 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.
Guide Tasks
  • Read Tutorial
  • Watch Guide Video
  • Complete the Exercise
Video locked
This video is viewable to users with a Bottega Bootcamp license

Summary

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 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.

Test Cases

Code File