我在从任务中调用 install_apache
函数时遇到困难:
task :install_apache => :environment do
begin
install_apache
rescue Exception => e
puts e
end
end
def install_apache
# code...
end
最佳答案
在Ruby 中,您必须首先定义一个方法。你使用语法来做到这一点
def method_name
# code goes here
end
要调用该方法,只需键入方法名称即可
method_name
在你的情况下,你已经迈出了第一步
def install_apache
end
您需要像这样在代码中添加另一行
install_apache
关于ruby-on-rails - 如何在 ruby 中调用函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26977671/