The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Just how many methods does Array have?

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Daniel Berger

Posts: 1383
Nickname: djberg96
Registered: Sep, 2004

Daniel Berger is a Ruby Programmer who also dabbles in C and Perl
Just how many methods does Array have? Posted: Dec 8, 2005 9:33 AM
Reply to this message Reply

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.
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Daniel Berger
Latest Posts From Testing 1,2,3...

Advertisement
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?

PS - Java sucks.

Read: Just how many methods does Array have?

Topic: Writing a Ruby Extension Tutorial Previous Topic   Next Topic Topic: Two Things

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use