On Wed, Jan 10, 2007 at 11:39:00PM +0900, Trans wrote:
> Sometimes i do this:
> 
>   return x if x
> 
> Anyway to code it as:
> 
>   return_on x
> 
> t.
> 
This is pure unadulterated evil, however it did come up in #ruby-lang a
while ago, so I whipped up some good old fashioned homemade evil:

def try_return(&block)
   unless (blah = block.call).nil?
      GC.disable
      eval("return ObjectSpace._id2ref(#{blah.object_id})", block)
   end
ensure
  GC.enable
end

def f
  try_return { nil }
  try_return { 7 }
  0
end

p f