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 > def executed? > re = /<(.*?)>/ # ? non-greedy, stops on first match > caller.to_s.match re # matches first text within <> in call-stack > #print caller.to_s > return $1 == "main" # first match was "main" means "executed" > end > end > > if executed? > print "EXEC mylib\n" > end > > #mytest.rb > require_relative 'mylib' > > if executed? > print "EXEC mytest\n" > end > > #maintest.rb > require_relative 'mylib' > require_relative 'mytest' > > if executed? > print "EXEC maintest\n" > end > > - > > ruby mylib.rb => EXEC mylib > ruby mylib.rb => EXEC mytest > ruby maintest.rb => EXEC maintest > > - > > I still dislike this solution, as it's not clean. What isn't "clean" about it? You've reduced: if __FILE__ == $0 to: if executed? The whole point of adding that method to Kernel is so you don't see the work it is doing, right? In a perfect world, what would you *like* the solution to look like? cr