Read more

Ruby: alias_method conflicting with prepend

Dominik Schöler
July 31, 2023Software engineer at makandra GmbH

alias_method makes a copy of a method. This works fine until the same method is overridden using prepend. If the prepend is executed after alias_method, you'll either see an infinite loop, or loose the prepended functionality.

Solution

Illustration online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
Read more Show archive.org snapshot

Your options are:

  • Ensure prepend happens before alias_method
  • If you can control the alias_method invocation: rewrite to the modern & better prepend
  • If you can only control the prepend invocation: rewrite to the legacy alias_method
Posted by Dominik Schöler to makandra dev (2023-07-31 10:13)