From: shevegen@... Date: 2017-05-21T17:29:50+00:00 Subject: [ruby-core:81319] [Ruby trunk Feature#13551] Add a method to alias class methods Issue #13551 has been updated by shevegen (Robert A. Heiler). > Given that it's very easy (as shown by Matthew) to create such a method, do you think it's necessary that this > be implemented by Ruby itself? You haven't yet answered the question about frequency of use or use cases. Well I do not have a statistical dataset myself, but I use it all the time. The thing is that for me it is very natural to use "alias". def foo; puts 'hi from foo()'; end alias bar foo I love it. I love aliases. They make me happy. :) I use aliases mostly because I have a bad memory. And also because I want to remain flexible. Some time ago I started to adopt a more "logical" scheme with my classes, when it may make sense. For example, most of my classes, if necessary, have a "reset" method. Often I also have a "menu" method, which I consider as the interface that can parse the commandline (or optionally any other input that is sent to it). And so on and so forth. So in this context, I totally agree with Joshua Stowers. I think that ruby itself should not care too much if a user wants to use an alias on the class/module level instance or within the context of self with regular instance methods of the class. So here, I agree with Joshua. The awkward thing, though, is that I actually dislike the syntax proposal: alias_class_method :new_name, :old_name The reason is, and this may be trivial, is that I really really hate the ',' character there. The symbols are ok although it's better to avoid them. I also understand that alias_method is not the same as alias, but alias is so cute and short, it is just built to be loved! Now you may wonder, how do I alias class methods then? I use a VERY clumsy way. I do not recommend anyone to use it and I am sure there are better ways but here goes: self.instance_eval { alias stop_codons stop_codons? } I dislike the self.instance_eval part because it is so long and verbose - but I love the alias part within the { } because to my eyes, it is neat and cuddly. I can't say whether I would use alias_class_method - the name is not soooo bad (though, what if we have a module Foo; end method? Do we call it alias_module_method then?), but I am not sure about the syntax. BUT I also dislike typing the: self.instance_eval { } part altogether, so in this context, I agree with Joshua Stowers. (I also understand that one should not use too many aliases but I love aliases. The main method is usually the one I use the most, and then I may use some aliases, some for backwards compatbility and sometimes I remove them too at a later point so it just provides some more flexibility "as you go".) Anything that would be as neat or almost as short as: "alias foo bar" but for class-methods / module-methods would be great! ---------------------------------------- Feature #13551: Add a method to alias class methods https://bugs.ruby-lang.org/issues/13551#change-65006 * Author: JustJosh (Joshua Stowers) * Status: Feedback * Priority: Normal * Assignee: * Target version: ---------------------------------------- There doesn't seem to be an intuitive way to alias class methods. Perhaps we can add a method such as ~~~ ruby alias_class_method :new_name, :old_name ~~~ -- https://bugs.ruby-lang.org/ Unsubscribe: