From: Daniel Berger Date: 2006-10-28T01:12:01+09:00 Subject: [PATCH] array.c - defining aliases as aliases ------=_Part_30117_83459.1161965517484 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline Hi all, This isn't nearly as sexy or glamorous as the String <=> Symbol discussion, but hey, sometimes it's the little things. ;) At the moment, the Array#map and Array#map! methods aren't officially defined as aliases. This seemingly trivial issue has one current problem and could potentially lead to issues in the future. The current (minor) problem is that rdoc doesn't properly document them as aliases. The potential problem for the future relates to an idea I had back at ruby-talk:196740. If ever we decide to add an Object.aliased_methods method (or whatever we call it), these methods would not show up. Then imagine a scenario where, after implementing Object.aliases_methods, someone implements a hack so that redefined methods also redefined the aliases, say through method_added. BTW, I would have also changed Array#indexes and Array#indices, but they appear to have some extra warning code, so aren't true aliases. Regards, Dan --- array.orig Fri Oct 27 09:16:31 2006 +++ array.c Fri Oct 27 09:18:27 2006 @@ -3014,8 +3014,8 @@ rb_define_method(rb_cArray, "sort!", rb_ary_sort_bang, 0); rb_define_method(rb_cArray, "collect", rb_ary_collect, 0); rb_define_method(rb_cArray, "collect!", rb_ary_collect_bang, 0); - rb_define_method(rb_cArray, "map", rb_ary_collect, 0); - rb_define_method(rb_cArray, "map!", rb_ary_collect_bang, 0); + rb_define_alias(rb_cArray, "map", "collect"); + rb_define_alias(rb_cArray, "map!", "collect!"); rb_define_method(rb_cArray, "select", rb_ary_select, 0); rb_define_method(rb_cArray, "values_at", rb_ary_values_at, -1); rb_define_method(rb_cArray, "delete", rb_ary_delete, 1); ------=_Part_30117_83459.1161965517484 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Hi all,

This isn't nearly as sexy or glamorous as the String <=> Symbol discussion, but hey, sometimes it's the little things. ;)

At the moment, the Array#map and Array#map! methods aren't officially defined as aliases.  This seemingly trivial issue has one current problem and could potentially lead to issues in the future.

The current (minor) problem is that rdoc doesn't properly document them as aliases.

The potential problem for the future relates to an idea I had back at ruby-talk:196740.  If ever we decide to add an Object.aliased_methods method (or whatever we call it), these methods would not show up.  Then imagine a scenario where, after implementing Object.aliases_methods, someone implements a hack so that redefined methods also redefined the aliases, say through method_added.

BTW, I would have also changed Array#indexes and Array#indices, but they appear to have some extra warning code, so aren't true aliases.

Regards,

Dan

--- array.orig  Fri Oct 27 09:16:31 2006
+++ array.c     Fri Oct 27 09:18:27 2006
@@ -3014,8 +3014,8 @@
     rb_define_method(rb_cArray, "sort!", rb_ary_sort_bang, 0);
     rb_define_method(rb_cArray, "collect", rb_ary_collect, 0);
     rb_define_method(rb_cArray, "collect!", rb_ary_collect_bang, 0);
-    rb_define_method(rb_cArray, "map", rb_ary_collect, 0);
-    rb_define_method(rb_cArray, "map!", rb_ary_collect_bang, 0);
+    rb_define_alias(rb_cArray, "map", "collect");
+    rb_define_alias(rb_cArray, "map!", "collect!");
     rb_define_method(rb_cArray, "select", rb_ary_select, 0);
     rb_define_method(rb_cArray, "values_at", rb_ary_values_at, -1);
     rb_define_method(rb_cArray, "delete", rb_ary_delete, 1); ------=_Part_30117_83459.1161965517484--