Override a method inside a gem from another gem

后端 未结 2 367
刺人心
刺人心 2021-01-20 16:24

Ok, I have a rails gem that I am working on and I want it to override a specific method in sprockets.

The method I want to override is: Sprockets::Base.digest so tha

2条回答
  •  遥遥无期
    2021-01-20 17:06

    Ok, I marked your answer correct, but it really only led me to figure out the problem.

    Anyway, the rails app was requiring my base file instead of the one in the gem itself. Which is what you said. However, the reason it was happening seems to have been caused by the path itself. The path to the file was basically the same as the gem's (lib/sprockets/base.rb).

    Moving that file into my gem's "namespace" (lib/my_gem instead of lib/sprockets) and renaming it to sprockets_base.rb fixed the problem! Weird, huh?

    In other words, me trying to keep the directory structure nice actually seems to have confused Rails into thinking it was the gem itself or something.

提交回复
热议问题