On Thu, 1 Feb 2001, David Alan Black wrote:
> Hello --
> Something which did surprise me quite a bit:
>   def rtest
>     pr = Proc.new do
>       return "Returning from closure"
>     end
>     pr.call
>     return "Returning from rtest"
>   end
>   puts rtest   # "Returning from closure"
> __END__
> Does that strike anyone else as unexpected?  



"return" returns from "real" methods; for closures you have to return
values "naturally", that is, by the value of the last expression in the
closure's body.

This feature allows for things such as:

class SomeArray
  def index(v)
    each_with_index {|x,i|
       return i if x==v
    }
    nil
  end
end



matju