Ruby on rails 包括2个具有相同方法的模块
我有一个特定的Ruby on rails 包括2个具有相同方法的模块,ruby-on-rails,ruby,module,Ruby On Rails,Ruby,Module,我有一个特定的控制器,它现在包括两个模块s class SomeController < ApplicationController include ModuleA include ModuleB def index if something? a_method # Method from ModuleA else b_method # Method from ModuleB end end end 如果我在两个模块中使
控制器
,它现在包括两个模块
s
class SomeController < ApplicationController
include ModuleA
include ModuleB
def index
if something?
a_method # Method from ModuleA
else
b_method # Method from ModuleB
end
end
end
如果我在两个模块中使用相同的方法名称(method
和other_method
),则method
从ModuleB
运行other_method
,我会得到一个错误
模块中是否可能有相同的方法名?我需要如何命名它们,以使method
从同一模块运行other\u method
,在该模块中实现它们
谢谢你的帮助 您得到了什么错误?模块在其实现中使用了Nokogiri,因此当
ModuleA
中的method
运行other\u method
时,我得到了Nokogiri错误。每个模块中大约有10种方法,它们相互连接。所以,我得到的错误是在模块实现中,当方法从不同的模块相互混合时。当所有方法在一个模块中运行时,没有错误。所以,某个错误消息不能帮助你回答我的问题,这不是因为模块实现,而是因为方法混合。你得到了什么错误?模块在实现中使用了Nokogiri,所以我得到了Nokogiri错误,当method
fromModuleA
运行other\u method
fromModuleB
时。每个模块中大约有10种方法,它们相互连接。所以,我得到的错误是在模块实现中,当方法从不同的模块相互混合时。当所有方法在一个模块中运行时,没有错误。所以,某个错误消息不能帮助您回答我的问题,这不是因为模块实现,而是因为方法混合。
module ModuleA
def a_method
a_other_method
...
end
private
def a_other_method
...
end
end
module ModuleB
def b_method
b_other_method
...
end
private
def b_other_method
...
end
end