From: Daniel Finnie Date: 2007-01-14T07:40:49+09:00 Subject: Re: return_on I have made the most hackish thing to accomplish this. It is basically a regexp-supporting preprocessor. I don't recommend using it. #! /usr/bin/ruby -w def preprocessor_define(*args, &blk) # Determine line of caller callerLine = caller.join.match(/[0-9]+/)[0].to_i # Get the source of the running file source = IO.read(__FILE__) # Remove the callerLine line source = source.split("\n") source.delete_at(callerLine - 1) source = source.join("\n") # Do the replacement source.gsub!(*args, &blk) # Avoid function redefinition warnings newName = "" 50.times {newName << (rand(26) + 65).chr } source.gsub!("preprocessor_define", newName) # Run the replacement #puts source eval source exit end preprocessor_define(/return_on (.*)/) {|s| "return #{s[1]} unless #{s[1]}.nil?"} def test zulu = 5 return_on zulu puts "Broken." end test Output: None, as 'puts Broken' never gets executed. Trans wrote: > Sometimes i do this: > > return x if x > > Anyway to code it as: > > return_on x > > t. > > >