From: Ilias Lazaridis Date: 2011-06-10T00:30:29+09:00 Subject: Re: CORE - Replace "if __FILE__ == $0" with "executed?" On 2 Ιούν, 16:30, Ilias Lazaridis wrote: > The construct to detect execution of the file (in order to launch main > code) looks like this: > > if __FILE__ == $0 >   main > end > > I would like a more elegant code. > > I try to implement a method in Kernel > > #myib.rb > module Kernel >   def executed? >     # detect in a clean way if the caller calls from an executed file >     # return true if so, else return false >   end > end > > #maintest.rb > require 'mylib' > if executed? >   print "works nice" > else >   print "seems to fail > end > > What would be the code for executed? related issue: Provide method Kernel#executed? http://redmine.ruby-lang.org/issues/4824 . -- http://lazaridis.com