This post originated from an RSS feed registered with Ruby Buzz
by Daniel Berger.
Original Post: Just how many methods does Array have?
Feed Title: Testing 1,2,3...
Feed URL: http://djberg96.livejournal.com/data/rss
Feed Description: A blog on Ruby and other stuff.
In my last entry I miscalculated just how many instance methods the Array class has. So, I went back and looked in array.c and enum.c just to make sure. Here are the final calculations. We're going to start with Enumerable first.
Enumerable has 22 instance methods.
Of those 4 are aliases - entries (to_a), find (detect), member? (include?) and select (find_all).
Array has 71 instance methods before mixing in Enumerable.
Of those 4 are aliases - map (collect), map! (collect!), size (length), and indices (indexes).
One method is deprecated - indexes.
So, let's remove the aliases and deprecated methods. That leaves us with 18 Enumerable methods and 66 Array methods.
Array mixes in Enumerable, so that leaves us with 84 instance methods, right? Not quite.
Of the 18 Enumerable methods mixed in, 7 have custom definitions - select, collect, sort, to_a, include?, reject and zip. These override the methods mixed in by Enumerable.
Lessee, 84 minus 7 is, uh, 77.
Oh, but wait! The select method is an alias in Enumerable, but has a custom definition in Array. That means Array#select isn't necessarily the same as Array#find_all. Or is it?
Oh, fuck it. I don't care any more. I'll be over here, getting some real work done, mmkay?