How to call function in ruby

ravi Teja

I am having difficulty calling the install_apache function from the task:

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

def install_apache
  # code...               
end
Darkmouse

In Ruby, you must first define a method. You do that using the syntax

def method_name
  # code goes here
end

To call the method, you simply type in the method name

method_name

In your case, you had the first step down

def install_apache
end

You need to add another line in your code like so

install_apache

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related