Exercises
- Can you extend the Ruby Array class to add similar support as in R to construct a continuous number sequence and to index through an array?
- Compare the supported operations for arrays in other languages.
- An array may be large, so it is useful to have a search method. In Ruby, we inquire whether an array supports a method such as grep. Let's take a leap of faith and try grep on the method array. Running Array.public_methods.grep "grep" you will find the answer is no. The returned array is empty. But this seems contradictory. Haven't we just used grep on an array?
August 29, 2012