17

我正在尝试使用以下方法覆盖 base_helper.rb 的辅助方法:

module Spree
  module BaseHelper.class_eval do

    def taxons_tree(root_taxon, current_taxon, max_level = 1)
      .....
    end

  end
end

它不适合我。有人知道我在这里想念什么吗?

谢谢!

固定的:

我应该使用:

Spree::BaseHelper.module_eval do

    def taxons_tree(root_taxon, current_taxon, max_level = 1)
      ...
    end

end

反而。

4

1 回答 1

23

重新打开模块也可以:

module Spree
  module BaseHelper
   def taxons_tree(root_taxon, current_taxon, max_level = 1)
      ...
   end
  end
end

class_eval使用and没有特别的理由module_eval,它只是 Spree 项目很长一段时间以来的习惯。

于 2012-08-22T14:26:32.213 回答