Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby equivalent to Python __main__ [duplicate]

If in a ruby file I define a function like so:

def tell_the_truth()
    puts "truth"
end

is there an equivalent to python's main?

if __name__ == "__main__":
    tell_the_truth()

Is it to simply call the function inside the file?

tell_the_truth
like image 948
Rodrigue Avatar asked Jul 19 '10 21:07

Rodrigue


2 Answers

I believe this will work:

if __FILE__ == $0
    tell_the_truth()
end
like image 177
robert Avatar answered Nov 11 '22 03:11

robert


if __FILE__ == $PROGRAM_NAME
    tell_the_truth()
end
like image 43
Uladzimir Avatar answered Nov 11 '22 01:11

Uladzimir