From: Michael Neumann Date: 2001-11-22T03:38:09+09:00 Subject: [ruby-talk:26055] Re: call_myself Tobias Reif wrote: > Hi all, > > sometimes, methods call itself inside. > ("Recursion"?") Yes, this is called recursion. > --- the example we all know--- > def fact(n) > if n == 0 > 1 > else > n * fact(n-1) > end > end > ------------------- > > Sometimes, this is not obvious, because there might me a lot of other code. > > def some_method arg > # many LOC > # some_method mod_arg > end > > Is there something that makes it clear that the method calls itself? Do you think of something like this (similar to Ocaml's let rec): def rec fact(n) if n == 0 1 else n * fact(n-1) end end No there's no such thing, but rec def fact(n) ... end would be possible if "def" would return a value (and not void). But do we really need this? I've never had problems with unwanted recursions. Regards, Michael -- Michael Neumann merlin.zwo InfoDesign GmbH http://www.merlin-zwo.de