January 14 - Finding the Average Value in an Array in Ruby
In this coding exercise you'll learn how to open the Array class and add an average method that finds the average value from an array of integers.
Guide Tasks
- Read Tutorial
- Watch Guide Video
- Complete the Exercise
Video locked
This video is viewable to users with a Bottega Bootcamp license
Already a Bottega Student? Sign In
Summary
Add an
average
method to Ruby'sArray
class that returns the average value of the integers in the array.
Exercise Description
Build a method that computes the average value of the elements in an Integer based array, and use monkey patching to add the method to the Array class.
Sample Method Call
[1, 2, 3].average # 2
Real World Usage
Running calculations on collections of data is a common requirement when it comes to Ruby development. Additionally, this exercise requires you to integrate monkey patching in order to add a method to a core Ruby class.