This post originated from an RSS feed registered with Ruby Buzz
by Daniel Berger.
Original Post: Synonyms vs Aliases
Feed Title: Testing 1,2,3...
Feed URL: http://djberg96.livejournal.com/data/rss
Feed Description: A blog on Ruby and other stuff.
I originally posted this on ruby-core but thought I'd blog it, too. I've posted before about the problem of determining which methods were "real" and which were aliases. One problem, as I mention in that link, is that that Ruby mostly uses synonyms instead of aliases in the source code.
For example, Array#map and Array#collect are synonyms but not true aliases, because of the way they're declared in array.c:
The Array#map method just refers to the same function as Array#collect, but it isn't an actual alias. If it were, it would have been declared like so:
rb_define_alias(rb_cArray, "map", "collect");
At this point you're probably thinking, "What's the big deal?". The big deal, in addition to making it impossible to calculate a given class' aliases at runtime, is that it screws up Method#==.
Here m1 and m2 are equal because Array#size and Array#length are true aliases (one of five in the core Ruby classes). Now watch what happens if we compare synonyms: