On 2 =C9=EF=FD=ED, 16:30, Ilias Lazaridis <il... / lazaridis.com> wrote:
> The construct to detect execution of the file (in order to launch main
> code) looks like this:
>
> if __FILE__ =3D=3D $0
> =A0 main
> end
>
> I would like a more elegant code.
>
> I try to implement a method in Kernel
>
> #myib.rb
> module Kernel
> =A0 def executed?
> =A0 =A0 # detect in a clean way if the caller calls from an executed file
> =A0 =A0 # return true if so, else return false
> =A0 end
> end
>
> #maintest.rb
> require 'mylib'
> if executed?
> =A0 print "works nice"
> else
> =A0 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