"Ara.T.Howard" <ahoward / fattire.ngdc.noaa.gov> wrote in message news:<Pine.LNX.4.44.0402130622000.31453-100000 / fattire.ngdc.noaa.gov>...

> return a value.  i was not clear enough, let me try again:
> 
> def meth s
>   x =
>     block_meth do
>       if s =~ /forty/
>         return 40
>       else
>         return 0
>       end
>     end
>   x + 2
> end
> 
> def block_meth; yield; end
> 
> p(meth('forty')) # this prints 40 - i want it to print 42 

The problem is that "return" returns from the enclosing method. The
code works as you want it to if you take out the "return" keywords,
like this:

def meth s
  x =
    block_meth do
      if s =~ /forty/
        40
      else
        0
      end
    end
  x + 2
end

def block_meth; yield; end

p(meth('forty')) # this prints 42