On 3 =C9=EF=FD=ED, 17:17, Chuck Remes <cremes.devl... / mac.com> wrote:
> On Jun 3, 2011, at 9:05 AM, Ilias Lazaridis wrote:
> > Using several constructs I saw, I came up with this one:
>
> > #mylib.rb
> > module Kernel
> > =A0def executed?
> > =A0 =A0re =3D /<(.*?)>/ =A0 =A0 =A0 =A0# ? non-greedy, stops on first m=
atch
> > =A0 =A0caller.to_s.match re =A0# matches first text within <> in call-s=
tack
> > =A0 =A0#print caller.to_s
> > =A0 =A0return $1 =3D=3D "main" =A0 # first match was "main" means "exec=
uted"
> > =A0end
> > end
>
> > if executed?
> > =A0print "EXEC mylib\n"
> > end
>
> > #mytest.rb
> > require_relative 'mylib'
>
> > if executed?
> > =A0print "EXEC mytest\n"
> > end
>
> > #maintest.rb
> > require_relative 'mylib'
> > require_relative 'mytest'
>
> > if executed?
> > =A0print "EXEC maintest\n"
> > end
>
> > -
>
> > ruby mylib.rb =3D> EXEC mylib
> > ruby mylib.rb =3D> EXEC mytest

correction:

ruby mytest.rb =3D> EXEC mytest

> > ruby maintest.rb =3D> EXEC maintest
>
> > -
>
> > I still dislike this solution, as it's not clean.
>
> What isn't "clean" about it?
[...]

I am criticising myself.

My implementation is not "clean", as it depends on the call stack /
regex.

.

--
http://lazaridis.com