Project

General

Profile

Actions

Feature #9185

open

Add alias_class_method or class_alias functionality

Added by shevegen (Robert A. Heiler) over 10 years ago. Updated about 6 years ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:58714]

Description

Hi core team,

First drink a Calpis (カルピス Karupisu) before reading on :-)

Now, my proposal is to add a slight new feature that is mostly one of convenience.

We have two ways to use aliases:

(1) alias
(2) alias_method

But are similar but not 100% the same.

Now this works all fine and nice.

But how to define a class method? Well, simple:

class Foo; def self.hi; puts 'hi'; end; end; Foo.hi

But how can we make an alias to this class method?

Well, this is ugly - here is one way:

class Foo; class << self; def ho; hi; end;end;end

Is this readable to you?

Using alias would be more readable.

Ok, we can simplify it by using alias:

class Foo; class << self; alias ho hi; end;end

But I don't like the class << self there, just to make
a single class alias.

I thus propose a new method called:

class_alias

The above could then be rewritte like so perhaps:
class Foo; class_alias :ho, :hi; end # I guess this would be more akin to alias_method

If the name is bad, it could be:

alias_class_method

Perhaps. Anyway, the name is not so important, I am sure a good name can be found,
but I wonder if this would be a good feature to add or not.

Thanks for reading!

Updated by nobu (Nobuyoshi Nakada) over 10 years ago

`class_alias' sounds like an alias of a class, to me, so the latter name feels better.

Anyway, it can implement in pure ruby, and you'd be able to make it as a gem.

Updated by hsbt (Hiroshi SHIBATA) about 10 years ago

  • Target version changed from 2.1.0 to 2.2.0
Actions #3

Updated by naruse (Yui NARUSE) about 6 years ago

  • Target version deleted (2.2.0)
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0