我想让以下内容发挥作用。我的想法是,我可以向路由添加方法,如果它们存在,我可以稍后使用它们。我正在使用 Ruby 1.8。
module Routes
def home
#stuff
end
def work
#end
end
end
Routes.method_defined? :home
# true
Routes.send(:home)
#NoMethodError: undefined method `home' for Routes:Module
最佳答案
使用以下代码,您可以做到这一点:
Class.new.extend(Routes).send(:home)
关于ruby - 如何通过反射调用 ruby 模块方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12674629/