Some Python programs have a couple lines of code like this:
if main == “main”
main()
I think it’s supposed to call the main function if the script is
executed
directly. Is there an equivalent in Ruby? Or is it even necessary in
Ruby?
(I’m new to Ruby, so excuse me if this is a stupid question.)
Mike S.
On Apr 20, 2007, at 11:39 AM, Mike S. wrote:
(I’m new to Ruby, so excuse me if this is a stupid question.)
Mike S.
I’m not entirely sure what that Python code means, but to do
something if the script is executed directly, you can try:
if FILE == $0
(do something)
end
These two snippets of code do the exact same thing: execute code if this
is
the source file being directly executed and not required (ruby) or
imported
(python).
Jason
On 4/20/07, Jason R. [email protected] wrote:
Some Python programs have a couple lines of code like this:
if main == “main”
I’m guessing the original poster probably meant this:
if name == ‘main’: