Howard Lewis Ship <hlship / gmail.com> Jan 6, 2005 at 08:11 AM wrote:
>I've had a couple of places where I really needed to return control from
a block to the method. What I'd prefer to write would be:
>Find.find(*ARGV) do |f|
>  if f =~ /[CVS|SVN]/ 
>    Find.prune
>    return-from-block-to-method
>  end
>  $matches += 1 if match?(f)
>end

By returning control to "the method," I think you mean as below. A
continuation sometimes is useful as a break (as here) and sometimes as a
continue statement. A fuller example is perhaps appropriate, as it's a
strange idea for non-Lisp programmers:

def aMethod
  # Following is a Ruby standard library kernel method
  # that makes a continuation object that when called,
  # transfers the program's flow of control to just below
  # its block.
  callcc do |afterCallccBlock|
    Find.find(*ARGV) do |f|
      if f =~ /[CVS|SVN]/ 
        Find.prune
        # Return-from-block-to-method
        afterCallccBlock.call # On to end of callcc block.
      end
      $matches += 1 if match?(f)
    end
  end
  # End of callcc block.
  # Rest of the method.
end # aMethod.