From: Gennady Date: 2003-12-05T08:32:31+09:00 Subject: Re: Generalized break? Joel VanderWerf wrote: > Hal Fulton wrote: > >> 2. I have a mild dislike for the idiom if $0 == __FILE__ (lines) end >> -- because I always indent inside an if, and I don't want to indent, >> and I really just want to say: break if $0 != __FILE__ > > > This seems to work: > > === x.rb === > puts "loading x.rb" > > alias old_load load > def load(*args) > catch :break_from_load do > old_load(*args) > end > end > > throw :break_from_load unless __FILE__ == $0 > > puts "a" > > load(__FILE__) > > puts "b" > ============ > > You get the following error when you 'require' this file: irb(main):001:0> require 'x' loading x.rb NameError: uncaught throw `break_from_load' from ./x.rb:11:in `throw' from ./x.rb:11 from (irb):1:in `require' from (irb):1 irb(main):002:0> Gennady.