< :前の番号
^ :番号順リスト
> :次の番号
P :前の記事(スレッド移動)
N :次の記事(スレッド移動)
|<:前のスレッド
>|:次のスレッド
^ :返事先
_:自分への返事
>:同じ返事先を持つ記事(前)
<:同じ返事先を持つ記事(後)
---:分割してスレッド表示、再表示
| :分割して(縦)スレッド表示、再表示
~ :スレッドのフレーム消去
.:インデックス
..:インデックスのインデックス
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: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>