Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix SystemStackError when extending the reload method with Module#pre…
…pend For example, when using the master branch of activerecord-multi-tenant, if activerecord-multi-tenant and attr_encrypted are listed in the Gemfile in that order, calling the reload method raises a SystemStackError. This happens because activerecord-multi-tenant extends Active Record’s reload method using prepend, while attr_encrypted extends it using an alias method. Here’s an example of how extending the same method with both prepend and alias methods in that order can result in a SystemStackError ``` class Hello def hello 'hello' end end Hello.prepend(Module.new do def hello super end end) Hello.class_eval do alias orig_hello hello def hello "#{orig_hello} world" end end Hello.new.hello #=> SystemStackError ``` However, reversing the order works: ``` class Hello def hello 'hello' end end Hello.class_eval do alias orig_hello hello def hello "#{orig_hello} world" end end Hello.prepend(Module.new do def hello super end end) Hello.new.hello #=> "hello world" ``` This issue can be resolved by standardizing the method extension to use prepend to avoid conflicts.
- Loading branch information