CSc 404 Assignment 3
That's Not Nice
Modify Ruby's built-in array class to contain method mean which returns
the mean (sum divided by count). If the array is empty, it
should return nil. If the array contains data
for which the needed computations are not allowed, your method would be
expected to crash. The numeric result should be floating point, even if the
members are integers.
Place your code a file with an .rb extension so it can be
brought in with load.
[bennet@m-mcc-csc-01456 ruby]$ irb
To do this, reopen the Array class and add the the method.
Your method body can use all the existing methods of the array class.
To call a method on yourself, use the object name self, which is
similar to the this in Java and C++.
For instance, you can subscript yourself with self[i].
Create a loop to add up all of your contents and return the result.
irb(main):001:0> load "mean.rb"
NoMethodError: undefined method `/' for "fredbarneysally":String
from /home/bennet/courses/cs404/asst/ruby/mean.rb:4:in `mean'
from /usr/bin/irb:12:in `<main>'
When your function works, is nicely formatted and documents,
submit it using