Issue #4824 has been updated by phluid61 (Matthew Kerwin).


dsferreira (Daniel Ferreira) wrote:
> phluid61 (Matthew Kerwin) wrote:
> 
> > For what it's worth, I think __main__ is best, or main?
> 
> I would agree with `main` in the following way:
>

`__main__`, not **main**.  Returns a boolean value, which can be used as a predicate:

~~~ruby
if __main__
  foo
end
~~~


----------------------------------------
Feature #4824: Provide method Kernel#executed?
https://bugs.ruby-lang.org/issues/4824#change-70782

* Author: lazaridis.com (Lazaridis Ilias)
* Status: Assigned
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version: 
----------------------------------------
The current construct to execute main code looks not very elegant:

~~~ruby
if __FILE__ == $0
  my_main()          # call any method or execute any code
end
~~~

With a `Kernel#executed?` method, this would become more elegant:

~~~ruby
if executed?
  #do this
  #do that
  my_main()
end
~~~

or

~~~ruby
main() if executed?
~~~

This addition would not break any existent behaviour.




-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>