# True method\_alias

**URL:** <https://forum.crystal-lang.org/t/true-method-alias/455>\
**Category:** Help & Support\
**Created:** [February 21, 2019, 8:28pm UTC](https://forum.crystal-lang.org/t/true-method-alias/455 "2019-02-21T20:28:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![duraki](https://avatars.discourse-cdn.com/v4/letter/d/8c91f0/32.png) [@duraki](https://forum.crystal-lang.org/u/duraki)\
**Post date:** [February 21, 2019, 8:28pm UTC](https://forum.crystal-lang.org/t/true-method-alias/455/1 "2019-02-21T20:28:26Z")

</div>

Crystal Wiki[1] says an alternative to Ruby `alias_method` is using `previous_def`. From what I can see, this doesn’t do much, compared to Ruby style. I’ve used and seen `alias_method` both in libraries (for deprecation support), and also in application types for execution of previous method definition (in specific cases, ie. shorthands).

Using `alias_method` is pretty simple in Ruby[2]. Just alias to previous definition, similar to what Crystal offers (ie. in inheritance).

Playground: [https://repl.it/repls/SpitefulUnevenGuiltware](https://repl.it/repls/SpitefulUnevenGuiltware)

```ruby
class User

  def full_name
    puts "Nur Yubr"
  end

  # Using `alias_method` to run previous declar
  alias_method :name, :full_name
end

User.new.name 

```

Using `perf_def` overwrites previous method declaration, as per the Wiki. This works well if inheritance is in use. But otherwise, we can’t _alias_ to previous method definition.

Playground: [https://play.crystal-lang.org/#/r/6btf](https://play.crystal-lang.org/#/r/6btf)

```crystal
class User

  def full_name
    puts "Nur Yubr"
  end

  # doesn't make much sense to use previous_def 
  # => previous_def
  
  # `alias` is not usable in this case
  # alias name = full_name
  
  # hacky alternative 
  def name
    full_name
  end
end

User.new.name

```

Any points? @Sija pointed asking @r00ster91, maybe he can share some detail. Anyway, looking forward to see alternatives.

---

<div class="post-metadata">

**Author:** ![asterite](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/asterite/32/60_2.png) [@asterite](https://forum.crystal-lang.org/u/asterite)\
**Post date:** [February 26, 2019, 10:12am UTC](https://forum.crystal-lang.org/t/true-method-alias/455/2 "2019-02-26T10:12:26Z")

</div>

The reason is that in Crystal we try to avoid aliases because they are redundant.

---

<div class="post-metadata">

**Author:** ![duraki](https://avatars.discourse-cdn.com/v4/letter/d/8c91f0/32.png) [@duraki](https://forum.crystal-lang.org/u/duraki)\
**Post date:** [February 28, 2019, 7:26pm UTC](https://forum.crystal-lang.org/t/true-method-alias/455/3 "2019-02-28T19:26:44Z")

</div>

What is the proper way to deprecate old methods while avoiding more `redundant` way I wrote above?

---

<div class="post-metadata">

**Author:** ![asterite](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/asterite/32/60_2.png) [@asterite](https://forum.crystal-lang.org/u/asterite)\
**Post date:** [February 28, 2019, 7:32pm UTC](https://forum.crystal-lang.org/t/true-method-alias/455/4 "2019-02-28T19:32:29Z")

</div>

You keep the old method for a version with a compile time warning. The next version you can turn that compile time warning into a compile time error. Then the next version you remove the method.
