ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: shevegen@gmail.com
To: ruby-core@ruby-lang.org
Subject: [ruby-core:81319] [Ruby trunk Feature#13551] Add a method to alias class methods
Date: Sun, 21 May 2017 17:29:50 +0000	[thread overview]
Message-ID: <redmine.journal-65006.20170521172950.d568a7c5825fa6b0@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-13551.20170509042019@ruby-lang.org

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/

  parent reply	other threads:[~2017-05-21 16:44 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <redmine.issue-13551.20170509042019@ruby-lang.org>
2017-05-09  4:20 ` [ruby-core:81046] [Ruby trunk Bug#13551] Add a method to alias class methods stowers.joshua
2017-05-09  7:09 ` [ruby-core:81056] [Ruby trunk Feature#13551][Feedback] " duerst
2017-05-09  7:19 ` [ruby-core:81058] [Ruby trunk Feature#13551] " matthew
2017-05-09 16:23 ` [ruby-core:81077] " stowers.joshua
2017-05-10  7:43 ` [ruby-core:81086] " duerst
2017-05-21 17:29 ` shevegen [this message]
2017-05-21 17:33 ` [ruby-core:81320] " shevegen
2017-06-14  3:07 ` [ruby-core:81676] " stowers.joshua
2017-06-14  3:08 ` [ruby-core:81677] " stowers.joshua
2017-09-25  8:13 ` [ruby-core:82973] [Ruby trunk Feature#13551][Rejected] " matz
2017-09-25  9:01 ` [ruby-core:82982] [Ruby trunk Feature#13551] " duerst

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.journal-65006.20170521172950.d568a7c5825fa6b0@ruby-lang.org \
    --to=ruby-core@ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).