From: danieldasilvaferreira@... Date: 2018-03-04T23:26:28+00:00 Subject: [ruby-core:85925] [Ruby trunk Feature#4824] Provide method Kernel#executed? Issue #4824 has been updated by dsferreira (Daniel Ferreira). graywolf (Gray Wolf) wrote: > Exactly, and the condition is: was this file directly executed?. We have two different contexts: * File context (FILE#executed?) - Was the file executed? * Code context (`Kernel#executable?`) - Is the code executable? I prefer to work at the code context level since we can then add other conditions to allow a code to be executable. e.g. ```ruby def executable? if __FILE__ == $0 && ARGV[1] == "foo" end ``` ---------------------------------------- Feature #4824: Provide method Kernel#executed? https://bugs.ruby-lang.org/issues/4824#change-70780 * 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: