ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:81046] [Ruby trunk Bug#13551] Add a method to alias class methods
       [not found] <redmine.issue-13551.20170509042019@ruby-lang.org>
@ 2017-05-09  4:20 ` stowers.joshua
  2017-05-09  7:09 ` [ruby-core:81056] [Ruby trunk Feature#13551][Feedback] " duerst
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 11+ messages in thread
From: stowers.joshua @ 2017-05-09  4:20 UTC (permalink / raw)
  To: ruby-core

Issue #13551 has been reported by JustJosh (Joshua Stowers).

----------------------------------------
Bug #13551: Add a method to alias class methods
https://bugs.ruby-lang.org/issues/13551

* Author: JustJosh (Joshua Stowers)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 
* Backport: 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN
----------------------------------------
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/

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [ruby-core:81056] [Ruby trunk Feature#13551][Feedback] Add a method to alias class methods
       [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 ` duerst
  2017-05-09  7:19 ` [ruby-core:81058] [Ruby trunk Feature#13551] " matthew
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 11+ messages in thread
From: duerst @ 2017-05-09  7:09 UTC (permalink / raw)
  To: ruby-core

Issue #13551 has been updated by duerst (Martin Dürst).

Status changed from Open to Feedback

What do you mean by 'intuitive'?

How frequent/important is this?

It's easily possible as follows:

```
class Array
  class << self
    alias :my_new :new
  end
end

Array.my_new # => []
```


----------------------------------------
Feature #13551: Add a method to alias class methods
https://bugs.ruby-lang.org/issues/13551#change-64703

* 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/

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [ruby-core:81058] [Ruby trunk Feature#13551] Add a method to alias class methods
       [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 ` matthew
  2017-05-09 16:23 ` [ruby-core:81077] " stowers.joshua
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 11+ messages in thread
From: matthew @ 2017-05-09  7:19 UTC (permalink / raw)
  To: ruby-core

Issue #13551 has been updated by phluid61 (Matthew Kerwin).


Do you mean singleton methods?

Something like this would work:

~~~ruby
module Kernel
  def alias_singleton_method new_name, old_name
    define_singleton_method(new_name) { old_name }
  end
end
~~~

~~~ruby
class Foo
  def self.bar
    :bar
  end

  alias_singleton_method :baz, :bar
end

Foo.bar  #=> :bar
Foo.baz  #=> :bar
~~~

----------------------------------------
Feature #13551: Add a method to alias class methods
https://bugs.ruby-lang.org/issues/13551#change-64704

* 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/

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [ruby-core:81077] [Ruby trunk Feature#13551] Add a method to alias class methods
       [not found] <redmine.issue-13551.20170509042019@ruby-lang.org>
                   ` (2 preceding siblings ...)
  2017-05-09  7:19 ` [ruby-core:81058] [Ruby trunk Feature#13551] " matthew
@ 2017-05-09 16:23 ` stowers.joshua
  2017-05-10  7:43 ` [ruby-core:81086] " duerst
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 11+ messages in thread
From: stowers.joshua @ 2017-05-09 16:23 UTC (permalink / raw)
  To: ruby-core

Issue #13551 has been updated by JustJosh (Joshua Stowers).


Thanks Matthew, that result is exactly what I had in mind.

Having to nest the logic within `class << self` makes it difficult to understand what is going on, and the code less readable.

----------------------------------------
Feature #13551: Add a method to alias class methods
https://bugs.ruby-lang.org/issues/13551#change-64728

* 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/

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [ruby-core:81086] [Ruby trunk Feature#13551] Add a method to alias class methods
       [not found] <redmine.issue-13551.20170509042019@ruby-lang.org>
                   ` (3 preceding siblings ...)
  2017-05-09 16:23 ` [ruby-core:81077] " stowers.joshua
@ 2017-05-10  7:43 ` duerst
  2017-05-21 17:29 ` [ruby-core:81319] " shevegen
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 11+ messages in thread
From: duerst @ 2017-05-10  7:43 UTC (permalink / raw)
  To: ruby-core

Issue #13551 has been updated by duerst (Martin Dürst).


JustJosh (Joshua Stowers) wrote:
> Thanks Matthew, that result is exactly what I had in mind.

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.

----------------------------------------
Feature #13551: Add a method to alias class methods
https://bugs.ruby-lang.org/issues/13551#change-64736

* 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/

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [ruby-core:81319] [Ruby trunk Feature#13551] Add a method to alias class methods
       [not found] <redmine.issue-13551.20170509042019@ruby-lang.org>
                   ` (4 preceding siblings ...)
  2017-05-10  7:43 ` [ruby-core:81086] " duerst
@ 2017-05-21 17:29 ` shevegen
  2017-05-21 17:33 ` [ruby-core:81320] " shevegen
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 11+ messages in thread
From: shevegen @ 2017-05-21 17:29 UTC (permalink / raw)
  To: ruby-core

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/

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [ruby-core:81320] [Ruby trunk Feature#13551] Add a method to alias class methods
       [not found] <redmine.issue-13551.20170509042019@ruby-lang.org>
                   ` (5 preceding siblings ...)
  2017-05-21 17:29 ` [ruby-core:81319] " shevegen
@ 2017-05-21 17:33 ` shevegen
  2017-06-14  3:07 ` [ruby-core:81676] " stowers.joshua
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 11+ messages in thread
From: shevegen @ 2017-05-21 17:33 UTC (permalink / raw)
  To: ruby-core

Issue #13551 has been updated by shevegen (Robert A. Heiler).


Martin showed this example:

> class Array
>   class << self
>     alias :my_new :new
>   end

Ruby allows this flexibility, this is true. This is also great, we
love it.

But when you use this code and want to distribute it, it is more
cumbersome. And not everyone likes to have modifications that
are non-standard ruby in their code.

I understand that the ruby team wants to be conservative and not
proliferate with lots of extra methods that have only a special
case (say active* gems), but to me I also completely understand
Joshua Stowers here - if possible it is MUCH, much better when
it would be in main ruby. So that everyone could use it.

- I may use it if it is in ruby core/stdlib.
- I may use duck patching (sometimes people use the monkey rather
than the duck) for my local code.
- But it is VERY unlikely that I would modify a core class of
ruby like this AND distribute my code to other people too. I
just consider it too cumbersome (and refinements, while the
idea is ok, I never really liked the syntax... and it felt
awkward... but this is for another discussion, lots of time
towards ruby 3.x I hope).

----------------------------------------
Feature #13551: Add a method to alias class methods
https://bugs.ruby-lang.org/issues/13551#change-65007

* 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/

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [ruby-core:81676] [Ruby trunk Feature#13551] Add a method to alias class methods
       [not found] <redmine.issue-13551.20170509042019@ruby-lang.org>
                   ` (6 preceding siblings ...)
  2017-05-21 17:33 ` [ruby-core:81320] " shevegen
@ 2017-06-14  3:07 ` stowers.joshua
  2017-06-14  3:08 ` [ruby-core:81677] " stowers.joshua
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 11+ messages in thread
From: stowers.joshua @ 2017-06-14  3:07 UTC (permalink / raw)
  To: ruby-core

Issue #13551 has been updated by JustJosh (Joshua Stowers).


I think Robert is exactly right.
I've hoped for such a method on several occasions myself, but highly dislike cluttering up the codebase with logic that is difficult to understand.
One of the best things about Ruby is that when written well it can read almost like English.

----------------------------------------
Feature #13551: Add a method to alias class methods
https://bugs.ruby-lang.org/issues/13551#change-65366

* 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/

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [ruby-core:81677] [Ruby trunk Feature#13551] Add a method to alias class methods
       [not found] <redmine.issue-13551.20170509042019@ruby-lang.org>
                   ` (7 preceding siblings ...)
  2017-06-14  3:07 ` [ruby-core:81676] " stowers.joshua
@ 2017-06-14  3:08 ` 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
  10 siblings, 0 replies; 11+ messages in thread
From: stowers.joshua @ 2017-06-14  3:08 UTC (permalink / raw)
  To: ruby-core

Issue #13551 has been updated by JustJosh (Joshua Stowers).


I think Robert is exactly right.
I've hoped for such a method on several occasions myself, but highly dislike cluttering up the codebase with logic that is difficult to understand.
One of the best things about Ruby is that when written well it can read almost like English. Such a method would help apply that further.

----------------------------------------
Feature #13551: Add a method to alias class methods
https://bugs.ruby-lang.org/issues/13551#change-65367

* 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/

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [ruby-core:82973] [Ruby trunk Feature#13551][Rejected] Add a method to alias class methods
       [not found] <redmine.issue-13551.20170509042019@ruby-lang.org>
                   ` (8 preceding siblings ...)
  2017-06-14  3:08 ` [ruby-core:81677] " stowers.joshua
@ 2017-09-25  8:13 ` matz
  2017-09-25  9:01 ` [ruby-core:82982] [Ruby trunk Feature#13551] " duerst
  10 siblings, 0 replies; 11+ messages in thread
From: matz @ 2017-09-25  8:13 UTC (permalink / raw)
  To: ruby-core

Issue #13551 has been updated by matz (Yukihiro Matsumoto).

Status changed from Feedback to Rejected

As Martin-sensei pointed out, use singleton class notation.

  class Foo
    class <<Foo
      def foo; end
      alias bar foo
    end
  end

I don't think it's worth adding a new method to avoid this simple thing.

Matz.


----------------------------------------
Feature #13551: Add a method to alias class methods
https://bugs.ruby-lang.org/issues/13551#change-66877

* Author: JustJosh (Joshua Stowers)
* Status: Rejected
* 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/

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [ruby-core:82982] [Ruby trunk Feature#13551] Add a method to alias class methods
       [not found] <redmine.issue-13551.20170509042019@ruby-lang.org>
                   ` (9 preceding siblings ...)
  2017-09-25  8:13 ` [ruby-core:82973] [Ruby trunk Feature#13551][Rejected] " matz
@ 2017-09-25  9:01 ` duerst
  10 siblings, 0 replies; 11+ messages in thread
From: duerst @ 2017-09-25  9:01 UTC (permalink / raw)
  To: ruby-core

Issue #13551 has been updated by duerst (Martin Dürst).


shevegen (Robert A. Heiler) wrote:
> Martin showed this example:
> 
> > class Array
> >   class << self
> >     alias :my_new :new
> >   end
> 
> Ruby allows this flexibility, this is true. This is also great, we
> love it.
> 
> But when you use this code and want to distribute it, it is more
> cumbersome. And not everyone likes to have modifications that
> are non-standard ruby in their code.

Sorry, I should have used another example than Array. This issue is about aliasing class methods, and aliasing a method in a builtin class would be a problem whether it's done with a new feature or with the way I showed. So the fact that I used Array is confusing, but orthogonal to the issue at hand.


----------------------------------------
Feature #13551: Add a method to alias class methods
https://bugs.ruby-lang.org/issues/13551#change-66890

* Author: JustJosh (Joshua Stowers)
* Status: Rejected
* 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/

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2017-09-25  9:01 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [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 ` [ruby-core:81319] " shevegen
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

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).