ruby-on-rails 如何在Ruby中调用函数

toe95027  于 2023-08-08  发布在  Ruby
关注(0)|答案(1)|浏览(80)

我很难从任务中调用install_apache函数:

task :install_apache => :environment do
  begin
    install_apache
  rescue Exception => e
    puts e
  end
end

def install_apache
  # Code...
end

字符串

ltskdhd1

ltskdhd11#

在Ruby中,你必须首先定义一个方法。你可以使用语法

def method_name
  # code goes here
end

字符串
要调用该方法,只需键入方法名

method_name


在你的情况下,你是第一步下台的

def install_apache
end


您需要在代码中添加另一行代码,如下所示

install_apache

相关问题